Why use Perl when we've got Python?!

John W. Stevens jstevens at basho.fc.hp.com
Sat Aug 14 05:01:12 CEST 1999

> In comp.lang.perl.misc, 
>     "John W. Stevens" <jstevens at basho.fc.hp.com> writes:
> :>     @array = ("fred", "wilma", "barney", "betty");
> :>     %hash  = @array;
> :> Is the same as:
> :>     %hash  = ("fred", "wilma", "barney", "betty");
> :> Because the list stored in the array will have its key-value pairs
> :> re-interpreted when this is stored into the hash.
> :
> :Resulting, again, in someting confusing to the programmer who
> :hasn't any idea of what the above does, and that is still
> :somewhat confusing even to an intermediate Perl programmer.
> :
> :I can *guess*, from my Perl experience, that this creates a hash whose
> :keys are the elements of the list, and that the data elements
> :mapped to those strings are . . . wait a minute, I'm not absolutely
> :sure.
> :
> :Let me try it. . . Ok, the data elements are set to either an integer
> :zero, or a string whose contents are the zero character, or a floating
> :point zero.
> Goodness no, it doesn't mean that at all.  Key-value pairs, dude.


When I tried it, then unmapped back, I got some kind of zero.

So much for DWIM.  Perl didn't do what I meant, there, and I couldn't
even guess, I had to try it.

And had I run across this idiom in a Perl program, I would have had harsh
words for the author, unless the code had been heavily documented.

John S.

More information about the Python-list mailing list