hash in scalar context

phillup on 2004-08-12T22:51:11

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.