Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

phillup (4419)

  (email not shown publicly)

Journal of phillup (4419)

Thursday August 12, 2004
05:51 PM

hash in scalar context

[ #20383 ]

While writing a test today I tried counting the number of elements in a hash by using the = operator. This gave me a value of '2/8'. Not what I expected when I wrote the code.

Then, I remembered that I needed to use 'keys' in a scalar context.

But, that '2/8' kept nagging at me... because I used to remember what it was. And, since I expected two key/value pairs, I was fairly sure I knew that the 2 represented that fact. But the 8 didn't make a lot of sense to me...

So, I went and looked it up.

...the value returned is a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash.

From Programming Perl.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.