Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2016-06-26 03:28 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (327 votes). Check out past polls.