Python vs. Perl

Tim Peters tim.one at home.com
Fri May 25 17:06:19 EDT 2001


[Thomas Wouters]
> ... Perl doesn't *have* integers that aren't strings. Perl just has
> scalars, lists and associative arrays. But the tuples-as-keys is a huge
> difference with perl hashes -- as far as I recall, that isn't possible.
> Hash keys have to be scalars. I remember that being one of the
> top-5 annoyances I had with Perl hashes :)

You fake it in Perl like so:

    $hash{$key1, $key2} = $whatever;

This is syntax magic that catenates the comma-separated sequence of keys
into a single string, separated by the current value of the $; magic vrbl.
That is, it's the same as

    $hash{"$key1$;$key2"} = $whatever;

While theoretically brittle, you usually <wink> manage to avoid trouble by
setting $; to an unlikely value; the default (Python chr(28)) usually works
fine.  God forbid you spell it

    @hash{$key1, $key2} = $whatever;

instead, though, as then the comma means something quite different.

baffled-by-why-i-remembered-this<wink>-ly y'rs  - tim





More information about the Python-list mailing list