Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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.

Cheers,

JohnGG


Comment on Re: Seeking explanation on assigning a hash to a scalar
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://615494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2014-10-24 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (137 votes), past polls