Mailing List Archive

converting perl to python - simple questions.
In my ongoing saga to build a chinese-language search engine, I've found a
great deal of groundwork already. The bad news (for me) is that this was all
in Perl so I've had a rather distressing day :
(a) learning perl
(b) converting the scripts to python so that I can build objects with them.

Anyway, since I know that there are a few ex-perlmongers on the list,
would somebody be so kind as to confirm whether I've translated the following
code snippets correctly :

a) Perl's "defined".
[perl]
if (defined($x{$token})

[python]
if (x.has_key(token) and x[token]!=None) :

b) RE's.
[perl]
if ($mytext !~ /^\s$/)

[python]
if not (re.match('^\s$'), mytext)


Since I know neither perl nor chinese, it would be nice if somebody
could help me remove one of the variables in my debugging.

Thanking you :)

chas






-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
converting perl to python - simple questions. [ In reply to ]
In article <7fvagp$8lm$1@nnrp1.dejanews.com>,
<sweeting@neuronet.com.my> wrote:
>
>a) Perl's "defined".
> [perl]
> if (defined($x{$token})
>
> [python]
> if (x.has_key(token) and x[token]!=None) :

That looks correct. Thankfully Python does have short-circuit
evaluation. Note that if you normally expect x[token] to have a value,
you might restructure the code a bit to use try/except.

>b) RE's.
> [perl]
> if ($mytext !~ /^\s$/)
>
> [python]
> if not (re.match('^\s$'), mytext)

I think you want

if not (re.match('^\s$', mytext)) :
or
if not (re.match('^\s*$', mytext)) :

(I think that Perl code has a bug in it by not including '*', but I
could be wrong.)
--
--- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

Hi! I'm a beta for SigVirus 2000! Copy me into your .sigfile!
converting perl to python - simple questions. [ In reply to ]
sweeting@neuronet.com.my writes:

> a) Perl's "defined".
> [perl]
> if (defined($x{$token})
>
> [python]
> if (x.has_key(token) and x[token]!=None) :

Depending on the code, you can omit the comparision to `None'. Perl
programmers traditionally uses `defined' to test if a key is in a hash,
so your code is the correct translation if you mimic Perl's undefined
value with Python's `None', but most of the time, this is not required.

> b) RE's.
> [perl]
> if ($mytext !~ /^\s$/)
>
> [python]
> if not (re.match('^\s$'), mytext)

Your Python code unconditionally executes the `false' branch of the
`if' statement. I hope this is the correct translation:

# Execute this once at the beginning of the program.
single_space = re.compile(r'^\s$') # use a r'aw' string

# Later on, you can try to match this regexp to a string:
if not single_space.match(mytext):

> Since I know neither perl nor chinese, it would be nice if somebody
> could help me remove one of the variables in my debugging.

I see. I've tried to install a Chinese text processing environment
for a friend. ;)
converting perl to python - simple questions. [ In reply to ]
[sweeting@neuronet.com.my]
> ...
> Anyway, since I know that there are a few ex-perlmongers on the list,
> would somebody be so kind as to confirm whether I've translated
> the following code snippets correctly :
>
> a) Perl's "defined".
> [perl]
> if (defined($x{$token})
>
> [python]
> if (x.has_key(token) and x[token]!=None) :

If should be enough to do

if x.has_key(token):

under the probably-correct theory that the Perl is just asking "does hash
'x' have key 'token'?" "None" is a specific valid value, not at all
"undefined", so checking x[token] against None doesn't make sense unless
you've established your own consistent program-wide convention of using None
to *mean* something like undefined. Which is dicey. After e.g. "del
x[token]", a reference to x[token] doesn't yield None, it raises the
KeyError exception.

> b) RE's.
> [perl]
> if ($mytext !~ /^\s$/)
>
> [python]
> if not (re.match('^\s$'), mytext)

Hmm. The Perl says "if mytext isn't a single whitespace character", which
is an odd thing to check! If that's the intent, fine. Python's "match"
already constrains the search to begin at the start of the string, so the
leading "^" isn't needed (use Python's "search" if don't want that
constraint). So:

if not re.match(r"\s$", mytext):

Get in the habit of using r-strings for writing regexps; they'll make your
backslash life much easier.

Another thing to note is that high-use regexps can be compiled, and if
they're always used in the same way (match vs search) you can capture that
choice too. So this may be more appropriate:

is_single_whitespace = re.compile(r"\s$").match

while whatever:
...
if not is_single_whitespace(mytext):
...
...

Hoisting the regexp compilation out of the loop can be a substantial win.

> Since I know neither perl nor chinese, it would be nice if somebody
> could help me remove one of the variables in my debugging.

native-speakers-of-both-say-chinese-is-easier-to-read<wink>-ly y'rs - tim
converting perl to python - simple questions. [ In reply to ]
On Sun, 25 Apr 1999 15:51:29 GMT, Aahz Maruch <aahz@netcom.com> wrote:
>In article <7fvagp$8lm$1@nnrp1.dejanews.com>,
> <sweeting@neuronet.com.my> wrote:
>>
>> [python]
>> if not (re.match('^\s$'), mytext)
>
>I think you want
>
> if not (re.match('^\s$', mytext)) :
>or
> if not (re.match('^\s*$', mytext)) :

Don't forget r'' in python when you have backslashes.

if not (re.match(r'^\s*$', mytext)):
converting perl to python - simple questions. [ In reply to ]
> > Anyway, since I know that there are a few ex-perlmongers on the list,
> > would somebody be so kind as to confirm whether I've translated
> > the following code snippets correctly :
> >
> > a) Perl's "defined".
> > [perl]
> > if (defined($x{$token})
> >
> > [python]
> > if (x.has_key(token) and x[token]!=None) :
>
> If should be enough to do
>
> if x.has_key(token):
>
> under the probably-correct theory that the Perl is just asking "does hash
> 'x' have key 'token'?" "None" is a specific valid value, not at all
> "undefined", so checking x[token] against None doesn't make sense unless
> you've established your own consistent program-wide convention of using None
> to *mean* something like undefined. Which is dicey. After e.g. "del
> x[token]", a reference to x[token] doesn't yield None, it raises the
> KeyError exception.

For years, I've been thinking of "None" in Python as "null" in javascript,
meaning "no value set" and so it was actually quite interesting to see that
Perl has "exists" and "defined" functions for dictionaries.... I had
translated "exists($dictionary{$token})" into "dictionary.has_key(token)"
and hence went overboard when I translated "defined(...)"

Anyway, from testing it does appear that both defined() and exists()
can be simply replaced with dico.has_key(token) in my scripts.


> > b) RE's.
> > [perl]
> > if ($mytext !~ /^\s$/)
> >
> > [python]
> > if not (re.match('^\s$'), mytext)
>
> Hmm. The Perl says "if mytext isn't a single whitespace character", which
> is an odd thing to check! If that's the intent, fine.

Yes, loads of double-byte character processing ...

> Python's "match"
> already constrains the search to begin at the start of the string, so the
> leading "^" isn't needed (use Python's "search" if don't want that
> constraint).

aaaah - subtle. Thanks.

>So:
>
> if not re.match(r"\s$", mytext):
>
> Get in the habit of using r-strings for writing regexps; they'll make your
> backslash life much easier.

Thank you for pointing that out - the perl stuff's been screwing
with my head and making me confused, \s being ok in that language.

> Another thing to note is that high-use regexps can be compiled, and if
> they're always used in the same way (match vs search) you can capture that
> choice too. So this may be more appropriate:
>
> is_single_whitespace = re.compile(r"\s$").match
>
> while whatever:
> ...
> if not is_single_whitespace(mytext):
> ...
> ...

Thank you very much - I'd read the excellent howto on python.org and that
described this too. I chose not to compile just for clarity since I'm still
trying to work out if I've translated the code from perl to python
correctly. But I will optimise later...

> Hoisting the regexp compilation out of the loop can be a substantial win.
>
> > Since I know neither perl nor chinese, it would be nice if somebody
> > could help me remove one of the variables in my debugging.
>
> native-speakers-of-both-say-chinese-is-easier-to-read<wink>-ly y'rs - tim

after today, i'd be inclined to agree :)

chas

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
converting perl to python - simple questions. [ In reply to ]
In article <m3u2u47hod.fsf@deneb.cygnus.stuttgart.netsurf.de>,
Florian Weimer <fw@cygnus.stuttgart.netsurf.de> wrote:
! sweeting@neuronet.com.my writes:
!
! > a) Perl's "defined".
! > [perl]
! > if (defined($x{$token})
! >
! > [python]
! > if (x.has_key(token) and x[token]!=None) :
!
! Depending on the code, you can omit the comparision to `None'. Perl
! programmers traditionally uses `defined' to test if a key is in a hash,
! so your code is the correct translation if you mimic Perl's undefined
! value with Python's `None', but most of the time, this is not required.

Just a point of clarification: Actually, perl programmer's
traditionally use 'exists' to test if a key is in a hash ... using
'defined' to test for key existence is a mistake---'defined' will
only tell you if that key exists and has a defined value associated
with it: Witness the defined test on key2 in the following:

#!/usr/bin/perl -w
use strict;
my %hash = ( key1 => 0,
key2 => undef,
key3 => 1
);
print "key1 exists\n" if exists $hash{key1};
print "key1 has defined value\n" if defined $hash{key1};
print "key1 has true value\n" if $hash{key1};

print "key2 exists\n" if exists $hash{key2};
print "key2 has defined value\n" if defined $hash{key2};
print "key2 has true value\n" if $hash{key2};

print "key3 exists\n" if exists $hash{key3};
print "key3 has defined value\n" if defined $hash{key3};
print "key3 has true value\n" if $hash{key3};
__END__

which prints:
key1 exists
key1 has defined value
key2 exists
key3 exists
key3 has defined value
key3 has true value

regards
andrew
converting perl to python - simple questions. [ In reply to ]
[sweeting@neuronet.com.my]

[Perl "exists"/"defined" vs Python "None"]
> For years, I've been thinking of "None" in Python as "null" in javascript,
> meaning "no value set"

Really not the same!

> and so it was actually quite interesting to see that Perl has "exists"
> and "defined" functions for dictionaries....

Perl is much more reluctant than Python to raise errors, and tends to return
"the undefined value" in situations where Python would kick you. So e.g.

%d = ();

($d{'hasa'}) = ('cat' =~ /(a)/);
print exists $d{'hasa'} ? "exists" : "not exists", "\n";
print defined $d{'hasa'} ? "defined" : "not defined", "\n";

($d{'hasa'}) = ('dog' =~ /(a)/);
print exists $d{'hasa'} ? "exists" : "not exists", "\n";
print defined $d{'hasa'} ? "defined" : "not defined", "\n";
print 2 + $d{'hasa'}, "\n";

prints:

exists
defined
exists
not defined
2

I'd rather get kicked <0.1 wink>. To be fair, adding 2 to the undefined
value will print a "use of uninitialized value" warning if Perl is run
with -w. I'd still rather get kicked. (BTW, always run Perl with -w! Even
Perl-heads will advise that <wink>. If the script you're translating relies
on extreme Perlish subtleties, -w will probably alert you to them.)

>> Get in the habit of using r-strings for writing regexps;
>> they'll make your backslash life much easier.

> Thank you for pointing that out - the perl stuff's been screwing
> with my head and making me confused, \s being ok in that language.

That's the problem! \s is fine in a Python string too. But other things
aren't, and without using r-strings you're responsible for remembering which
is which. For example, the regexp

r"\bthe"

matches "the" starting at a word boundary, but the regexp

"\bthe"

matches "the" following a backspace character.

Perl actually has the same problem, but it's *usually* hidden by "regexp
context"; e.g.;

$string =~ /\bthe/

matches "the" starting at a word boundary, while

$pattern = "\bthe";
$string =~ /$pattern/

matches "the" following a backspace character. Perl treats string escape
sequences differently depending on whether the string is or isn't in regexp
context; Python has no concept of context, so always treats string escapes
the same way; the feature of Python r-strings is that they don't do *any*
backslash substitutions, allowing the callee (in this case, re and pcre) to
treat them as *it* wants to.

Subtleties aside, most Perl5 regexps work fine in Python after replacing the
bracketing / and / with r" and ". OTOH, if you can use a facility from the
string module instead, it's usually clearer and faster; e.g., the original

$x !~ /^\s$/

may be better as

not (len(x) == 1 and x in string.whitespace)

depending on what the original line is *really* trying to do (did they
really want all of " ", "\n", " \n", and "\n\n" to match? beats me ... and
that's one reason a string version is clearer).

all-bleeding-stops-ly y'rs - tim
converting perl to python - simple questions. [ In reply to ]
In article <000001be8f3e$eea9c3c0$d39e2299@tim>,
Tim Peters <tim_one@email.msn.com> wrote:
>[sweeting@neuronet.com.my]
>> ...
>> Anyway, since I know that there are a few ex-perlmongers on the list,
>> would somebody be so kind as to confirm whether I've translated
>> the following code snippets correctly :
>>
>> a) Perl's "defined".
>> [perl]
>> if (defined($x{$token})
>>
>> [python]
>> if (x.has_key(token) and x[token]!=None) :
>
>If should be enough to do
>
> if x.has_key(token):
>
>under the probably-correct theory that the Perl is just asking "does hash
>'x' have key 'token'?"

Try "definitely wrong theory" ;-). In Perl, exists($x{$token}) is
precisely equivalent to Pyton's x.has_key(token), and you can either use
defined($x{$token}) or $x{$token}!=undef to make sure that a value
exists for that key. Thing is, in Perl you can go straight to checking
the value because a non-existant key is not an error.

(I won't quite call myself a Perl expert, but I'm pretty close to an
expert on Perl hashes.)
--
--- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

Hi! I'm a beta for SigVirus 2000! Copy me into your .sigfile!
converting perl to python - simple questions. [ In reply to ]
[about Perl "if (defined($x{$token})"]

[.Tim sez "under the probably-correct theory that the Perl is just
asking "does hash 'x' have key 'token'?"]

[Aahz Maruch]
> Try "definitely wrong theory" ;-). In Perl, exists($x{$token}) is
> precisely equivalent to Pyton's x.has_key(token), and you can either use
> defined($x{$token}) or $x{$token}!=undef to make sure that a value
> exists for that key. Thing is, in Perl you can go straight to checking
> the value because a non-existant key is not an error.
>
> (I won't quite call myself a Perl expert, but I'm pretty close to an
> expert on Perl hashes.)

But most Perl programmers aren't, and I've suffered thru enormous piles of
Perl code that used "defined" where "exists" was appropriate. That's where
my "probably" comes from: not talking about what the language does, but
what the programmer probably *intended*. In the absence of more information
about what the original script does, my guess is still that the author
*intended* "exists" == has_key.

not-all-perl-code-is-well-written<wink>-ly y'rs - tim
converting perl to python - simple questions. [ In reply to ]
aahz@netcom.com (Aahz Maruch) writes:

> In article <7fvagp$8lm$1@nnrp1.dejanews.com>,
> <sweeting@neuronet.com.my> wrote:
> >
> >a) Perl's "defined".
> > [perl]
> > if (defined($x{$token})
> >
> > [python]
> > if (x.has_key(token) and x[token]!=None) :
>
> That looks correct. Thankfully Python does have short-circuit
> evaluation. Note that if you normally expect x[token] to have a value,
> you might restructure the code a bit to use try/except.
>

wouldn't x.get() work more elegantly:
---
if (x.get(token)) :
[do stuff]
---


--
-chad
converting perl to python - simple questions. [ In reply to ]
In article <x1ju2u3xmo0.fsf@unhinged.engr.sgi.com>,
Chad McDaniel <chadm@sgi.com> wrote:
>aahz@netcom.com (Aahz Maruch) writes:
>> In article <7fvagp$8lm$1@nnrp1.dejanews.com>,
>> <sweeting@neuronet.com.my> wrote:
>>>
>>>a) Perl's "defined".
>>> [perl]
>>> if (defined($x{$token})
>>>
>>> [python]
>>> if (x.has_key(token) and x[token]!=None) :
>>
>> That looks correct. Thankfully Python does have short-circuit
>> evaluation. Note that if you normally expect x[token] to have a value,
>> you might restructure the code a bit to use try/except.
>
>wouldn't x.get() work more elegantly:
>---
>if (x.get(token)) :
> [do stuff]

Yup. I keep forgetting about that one. Note that (cf recent thread)
"if ( not x.get(token) is None ) :" is faster in many cases.
--
--- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

Hi! I'm a beta for SigVirus 2000! Copy me into your .sigfile!
converting perl to python - simple questions. [ In reply to ]
andrew-johnson@home.com (Andrew Johnson) writes:

> Just a point of clarification: Actually, perl programmer's
> traditionally use 'exists' to test if a key is in a hash ...

No, unfortunately that's wrong:

| defined(EXPR)
|
| defined EXPR
| Returns a boolean value saying whether the lvalue
| EXPR has a real value or not. Many operations
| return the undefined value under exceptional con-
| ditions, such as end of file, uninitialized vari-
| able, system error and such. This function allows
| you to distinguish between an undefined null
| string and a defined null string with operations
| that might return a real null string, in particu-
| lar referencing elements of an array. You may
| also check to see if arrays or subroutines exist.
| Use on predefined variables is not guaranteed to
| produce intuitive results. Examples:
|
| print if defined $switch{'D'};
| [...]

(Quotation from the Perl 4 manpage. This version doesn't have an
`exists' function.)

> using
> 'defined' to test for key existence is a mistake---'defined' will
> only tell you if that key exists and has a defined value associated
> with it: Witness the defined test on key2 in the following:

Of course you are right. That's the reason why `exists' was introduced
-- I guess in Perl 5.
converting perl to python - simple questions. [ In reply to ]
In article <m3so9lc219.fsf@deneb.cygnus.stuttgart.netsurf.de>,
Florian Weimer <fw@cygnus.stuttgart.netsurf.de> wrote:
>
>(Quotation from the Perl 4 manpage. This version doesn't have an
>`exists' function.)

Then you've just made a completely irrelevant comment, on the order of
referring to Python 1.2. Perl 5 has been out for more than two years,
and there are so many improvements that I don't know of *anyone* who's
doing new work in Perl 4.
--
--- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

Hi! I'm a beta for SigVirus 2000! Copy me into your .sigfile!
converting perl to python - simple questions. [ In reply to ]
Aahz Maruch <aahz@netcom.com> wrote:
: In article <m3so9lc219.fsf@deneb.cygnus.stuttgart.netsurf.de>,
: Florian Weimer <fw@cygnus.stuttgart.netsurf.de> wrote:
:>
:>(Quotation from the Perl 4 manpage. This version doesn't have an
:>`exists' function.)

: Then you've just made a completely irrelevant comment, on the order of
: referring to Python 1.2. Perl 5 has been out for more than two years,
: and there are so many improvements that I don't know of *anyone* who's
: doing new work in Perl 4.

Perl 5 was released somewhere around 3-4 years ago. And I haven't
written much Perl code in that time - but any Perl code I have written
is for perl4. I avoid perl5 religiously.

But there could easily be others out there who still use perl4 as well.
Just like there are ppl out there who still use Tcl 7.5 (my previous
and current employers) and Python 1.4. It is not always easy to
upgrade when you have to support customers in the field using
real-world products.

-Arcege
converting perl to python - simple questions. [ In reply to ]
aahz@netcom.com (Aahz Maruch) writes:

| In article <m3so9lc219.fsf@deneb.cygnus.stuttgart.netsurf.de>,
| Florian Weimer <fw@cygnus.stuttgart.netsurf.de> wrote:
| >
| >(Quotation from the Perl 4 manpage. This version doesn't have an
| >`exists' function.)
|
| Then you've just made a completely irrelevant comment, on the order
| of referring to Python 1.2. Perl 5 has been out for more than two
| years, and there are so many improvements that I don't know of
| *anyone* who's doing new work in Perl 4.

Four and a half, actually; Perl 5.000 was released in October 1994,
exactly a week after Python 1.1. In fact, Perl 5 has been the current
version longer than Perl 4 was (Perl 4 was released in March 1991, so
it was the newest version for only three and a half years).

(References: perlhist manpage, and Misc/HISTORY in the Python source
distribution.)

--
Dan Schmidt -> dfan@harmonixmusic.com, dfan@alum.mit.edu
Honest Bob & the http://www2.thecia.net/users/dfan/
Factory-to-Dealer Incentives -> http://www2.thecia.net/users/dfan/hbob/
Gamelan Galak Tika -> http://web.mit.edu/galak-tika/www/
converting perl to python - simple questions. [ In reply to ]
[Aahz Maruch]
> ...
> Perl 5 has been out for more than two years, and there are so many
> improvements that I don't know of *anyone* who's doing new work
> in Perl 4.

I do -- one crusty Unix sysadmin in particular who doesn't trust "all that
new stuff", still using his "better the devil you know" <wink> old Perl4.
He won't use Python either. I subscribe him to functional-language mailing
lists just to keep him off balance <wink>.

perl-has-72-iterations-to-go-to-catch-up-to-fortran77-ly y'rs - tim
converting perl to python - simple questions. [ In reply to ]
>>>>> "Dan" == Dan Schmidt <dfan@harmonixmusic.com> writes:

Dan> Four and a half, actually; Perl 5.000 was released in October 1994,
Dan> exactly a week after Python 1.1. In fact, Perl 5 has been the current
Dan> version longer than Perl 4 was (Perl 4 was released in March 1991, so
Dan> it was the newest version for only three and a half years).

Not to mention that *all* versions of Perl prior to 5.004 have known,
documented buffer-overflow potential problems, so if you use those
scripts in any public-execution environment (like CGI or setuid
programs or daemons), you are setting yourself up for a "non use of
best practices" lawsuit when the bad guys break in.

I'm told by people in-the-know of a rootkit that targets *any* CGI
script and sends it the right thing to break in, presuming you know
the arch of the box and have a reasonable guess as to the Perl
version.

Perl 4 is dead. Anything before 5.004 is dangerous. Perl5 *is* Perl.

Just another Perl (and Python) hacker,

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
converting perl to python - simple questions. [ In reply to ]
>>>>> "Tim" == Tim Peters <tim_one@email.msn.com> writes:

Tim> Perl actually has the same problem, but it's *usually* hidden by "regexp
Tim> context"; e.g.;

Tim> $string =~ /\bthe/

Tim> matches "the" starting at a word boundary, while

Tim> $pattern = "\bthe";
Tim> $string =~ /$pattern/

Tim> matches "the" following a backspace character.

Oddly enough, these *will* match word boundaries:

$pattern = '\bthe';

$pattern = qr/\bthe/;

Yes, Perl is heavily context sensitive... and so are human beings. :)

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
converting perl to python - simple questions. [ In reply to ]
On 29 Apr 1999, Randal L. Schwartz wrote:

> >>>>> "Tim" == Tim Peters <tim_one@email.msn.com> writes:
>
> Tim> Perl actually has the same problem, but it's *usually* hidden by "regexp
> Tim> context"; e.g.;
<snipped examples by Tim, and counter exampales by Randal>

> Yes, Perl is heavily context sensitive... and so are human beings. :)

I wonder if Randal came here (2 messages in this group) to spread the
regular Perl propaganda (summarized by "This language is icky because
programmers are icky")....

Randal, while I'm sure you're a good guy, and I liked ``Learning Perl'',
most of us at c.l.py heard more about Perl then we'll ever want to --
in fact, I think many of us moved to Python from Perl, and never looked
back. (Or we'd turn into salt)

(And hey, Randal, when you wake up and start using Python, I'm sure you'll
be one of the best c.l.py posters <0.5 wink>)

and-one-day-larry-wall-will-help-maintain-python-too-ly y'rs, Z.
--
Moshe Zadka <mzadka@geocities.com>.
QOTD: My own exit is more likely to be horizontal then perpendicular.
converting perl to python - simple questions. [ In reply to ]
[Tim and Randal Schwartz exchange Perl quotes <ahem>]

[Randal]
> ...
> Yes, Perl is heavily context sensitive... and so are human beings. :)

[Moshe Zadka]
> I wonder if Randal came here (2 messages in this group) to spread the
> regular Perl propaganda (summarized by "This language is icky because
> programmers are icky")....

Na. Randal's occasional visits to c.l.py have always been pleasant. In
fact, he should hang out here more often!

Here's a topic for civil debate: Resolved: returning different stuff
depending on whether an expression is in array or scalar context is no worse
than killing those of your classmates wearing shirts with sports insignia
<wink>.

oh-ya?-i'll-see-that-and-raise-you-two-hitlers-ly y'rs - tim
converting perl to python - simple questions. [ In reply to ]
Uncle Tim said:
> Here's a topic for civil debate: Resolved: returning different stuff
> depending on whether an expression is in array or scalar context is no
> worse than killing those of your classmates wearing shirts with sports
> insignia <wink>.

Using the formalism of symbolic algebra we start with the universe
of concepts denoted U. We choose two items, A,B which are elements
of U such that:

A = "returning different stuff depending on whether an expression is
in array or scalar context"

and

B = "killing those of your classmates wearing shirts with sports
insignia"


It is obvious that there exists some metric M which induces an
ordering in U such that if X,Y are elements of U then the statement
"X is worse than Y" is either correct or incorrect. We denote "X
is worse than Y" by the expressions "X > Y" or "Y < X". The other
standard expression for equality and inequality apply as normal,
and it should be observed that this is a partial ordering as there
can be some X,Y in U where X < Y and X > Y are both incorrect (so
X == Y) using M but X is not identical to Y in U.

We can derive such a metric M through newscasts and other forms of
media. From this it is a relatively trivial matter to conclude that

A < B

given M(media) on U. Hence it is seen that it is not true that B >= A
and so the statement proposed by <tim_one@email.msn.com> in his
paper <000201be929f$636d10a0$5fa02299@tim>.

"returning different stuff depending on whether an expression is
in array or scalar context is no worse than killing those of your
classmates wearing shirts with sports insignia"

is a correct one, and that we can make the even stronger assertion

"returning different stuff depending on whether an expression is
in array or scalar context is less worse than killing those of
your classmates wearing shirts with sports insignia"

as the equivalence case has been shown to be false for the given
M(media). It remains to be seen if there exists some M for which
these statements are incorrect.

(Whew - got that math lingo coursing through my system now, and
hence we see that I should halt before I further such discussions :)

Andrew
dalke@acm.org