[Omaha.pm] print "%hash";

Andy Lester andy at petdance.com
Tue Oct 16 15:59:24 PDT 2007


On Oct 16, 2007, at 5:55 PM, Travis McArthur wrote:

> That's rather unusual but very useful, I don't know any other language
> that has built in hashing functionality to have that sort of
> instrumentation (regarding allocated buckets versus full buckets).  I
> never knew that!  Awesome stuff, I like how Perl pretty intelligently
> guesses what you want to know, which is nice.  Thanks for bringing  
> this
> up Jay.

It also comes back as a plain zero if no buckets are used, because  
the hash is empty, so you can check to see if the hash is empty just  
by looking at it in scalar context.

Got some keys:
alester:~ $ perl -le'print scalar %ENV'
26/64

This hash has no keys:
alester:~ $ perl -le'print scalar %nonexistenthash'
0

We've deleted all the keys that used to be there:
alester:~ $ perl -le'delete @ENV{keys %ENV};print scalar %ENV'
0






--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance






More information about the Omaha-pm mailing list