Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Seeking explanation on assigning a hash to a scalar

by johngg (Abbot)
on May 15, 2007 at 09:07 UTC ( #615494=note: print w/replies, xml ) Need Help??

in reply to Seeking explanation on assigning a hash to a scalar

imp and Samy_rio have shown you the documentation that demonstrates that there is a meaning to the result you got. Perhaps you were expecting the assignment of a hash to a scalar to behave in a similar way to assigning an array to a scalar, i.e. give the number of keys and values in the hash. If that was what you wanted you can do that like this

use strict; use warnings; my %hash = (a => 1, b => 2, c => 3); my $buckets = %hash; my $elems = () = %hash; print qq{ Buckets: $buckets\nElements: $elems\n};

which prints

Buckets: 3/8 Elements: 6

I hope this is of interest.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://615494]
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-06-27 09:34 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (601 votes). Check out past polls.