Python vs. Perl
Thomas Wouters
thomas at xs4all.net
Sat May 26 05:17:03 EDT 2001
On Sat, May 26, 2001 at 08:50:53AM +0200, Alex Martelli wrote:
> Ah, the keys in a dictionary (hash) display are taken as literal
> and the values aren't? How quaint. I used to know Perl pretty
> well and wrote tens thousands of lines in it -- I'm so glad I am
> at last forgetting its gyrations!-) Is it a stropping issue? Why
> are the quotes needed after the '=>'s -- or, ARE they?
The trick is in the => construct. It has no special dict (err, hash)
meaning. In perl, hashes are just flat lists of key,value pairs. So a dict
literal would be:
('key1', 'value1', 'key2', 'value2');
Or, if you want to create an anonymous dict (this evaluates to a reference
to a dict -- does it look familiar ?)
{'key1', 'value2', 'key2', 'value2'};
The => token simply quotes the preceding token, and then translates itself
into a comma. So
{key1 => 'value1', key2 => 'value2'};
is the same as the second example above.
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list