Python vs. Perl

Gisle Aas gisle at ActiveState.com
Sat May 26 00:17:33 EDT 2001


Paul Prescod <paulp at ActiveState.com> writes:

> I think I just did. You agreed with me that Perl couldn't easily use
> just any object as a key, allow any object to describe how it hashes
> itself or easily allow any object to act syntactically as a dictionary.

Any object can be key in a Perl hash.  The difference is that Perl
will use the stringified value as key so you don't get back the
objects when you ask for 'keys %hash'.  In practice this is seldom a
problem as perl by default stringify objects in interesting ways.
Where you would use tuples as keys in Python you would use multilevel
hashes in Perl.  Perl's autovivification makes use of multilevel hashes
for this purpose easy.

Perl objects can define how they are hashed by overriding how they are
stringified.

Perl objects can easily act syntactically as a hashes.  These
hash-like objects is not limited to keys-are-strings as the builtin
hashes are.  It is thus fairly easy to emulate python like dicts in
Perl.  It's just seldom any use for that.

> I'm not going to claim based on that that Python is better than Perl but
> I think it is pretty clear that Python dictionaries are more flexible
> and easy to use than Perl hashes.

I can agree that they are more flexible.  I would not agree on the
ease of use claim.  I think it is pretty clear that Perl hashes will
be faster than Python dicts.

-- 
Gisle Aas



More information about the Python-list mailing list