carpe linguam

Tim Peters tim_one at email.msn.com
Fri Aug 27 00:06:24 EDT 1999


[Michael Hudson]
[... skipping all the interesting stuff to save time <wink> ...]

> Python isn't perfect; anyone who claims it is is either lying or
> stupid.

Or, in my case, both!

> I much prefer it to perl, but that says as much about me as
> about the languages.

I still use Perl for many a text-crunching one-shot (it's fast and convenient!
can't beat it for that), but spend far too much time helping others track down
their Perl bugs.  Here's one that popped up at work today:

    @a = (1 .. 100);
    $sum = 0;
    foreach (@a) { $sum += $_; }
    print "sum $sum\n";
    print "length ", length(@a), "\n";

That prints:

    sum 5050
    length 3

3?  Oh yes:  the array @a is in scalar context, and in this particular flavor
of scalar context returns its length.  The "length" function then sees 100, and
goes "aha! so how many characters does 100 consume when converted to a decimal
string?".  Three, and "perl -w" doesn't complain.

I've seen that before, so it didn't take long to track down.  But if you're
looking for a good reason to prefer Python for some tasks, it's not a challenge
to find about three of them in that example <0.3 wink>.

do-what-i-don't-mean-ly y'rs  - tim






More information about the Python-list mailing list