in reply to Perl oddities
From perldata:$ perl -le '%h = (a =>1, b => 2); print scalar %h' 2/8
If you evaluate a hash in scalar context ... the value returned is a string consisting of the number of used buckets and the number of allocated buckets ...
Buckets!
I can't imagine that this is useful to anyone except the implementor of the hashing function and the occasional person with pathological data.
It would be much more useful, or sensible, if hash in a scalar context returned the number of keys:
$ perl -le '%h = (a =>1, b => 2); print scalar keys %h' 2
And before anyone leaps to the defense of this artifact I'm just stating that I find it odd. I can live with it.
I think that there were a lot of things that I used to find odd but since I can't remember what they are I guess that I've just come to accept them. :-)
--
John.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl oddities
by TimToady (Parson) on Mar 01, 2005 at 18:25 UTC | |
|
Re^2: Perl oddities
by PreferredUserName (Pilgrim) on Mar 01, 2005 at 14:54 UTC | |
by mojotoad (Monsignor) on Mar 02, 2005 at 21:12 UTC | |
|
Re^2: Perl oddities
by fergal (Chaplain) on Mar 01, 2005 at 16:04 UTC | |
by jmcnamara (Monsignor) on Mar 01, 2005 at 16:26 UTC | |
by fergal (Chaplain) on Mar 01, 2005 at 18:19 UTC |