Hey, that's was pretty slick. crazysniffable, if you're not sure what's going on, here's the scoop:
The map operator takes an array and loops over each element. In this case, the array is the keys of %hash. In srawls' code for map, he's asking for it to return the keys to the anonymous hash at $hash{$_}. Since he's evaluating it in scalar context, it returns the total number of elements, instead of the keys. This code is equivalent to:
Of course, as srawls mentioned, it loops. There's really no way around this (that I can see).my $numSubKeys = 0; foreach ( keys %hash ) { $numSubKeys += scalar keys %{$hash{$_}} }; }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: Re: scalar subkeys %hash ?
by Ovid
in thread scalar subkeys %hash ?
by crazysniffable
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |