Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: number of keys and values in a hash

by pvaldes (Chaplain)
on Oct 11, 2011 at 15:05 UTC ( #930841=note: print w/replies, xml ) Need Help??


in reply to Re^2: number of keys and values in a hash
in thread number of keys and values in a hash

well, of course you will need to create and fill a hash first with the desired part of your data. The code tells you exactly what you have: my %nums =( "$number", $info) is a hash with one element only, a single pair key-value. You need to iterate between all keys and all values

Replies are listed 'Best First'.
Re^4: number of keys and values in a hash
by pvaldes (Chaplain) on Oct 11, 2011 at 15:47 UTC

    Some extra notes about your code:

    while (my ($keys, $values) = each %nums) {

    is probably a little more readable than

    while ((my $keys, my $values) = each (%nums)) {

    and you could prefer also to use

    open my $file, 'formal.xml'; instead: my $file;open $file, 'formal.xml');

    and print "num: $number\n"; instead: print( "num: $number\n" );

Re^4: number of keys and values in a hash
by veerubiji (Sexton) on Oct 12, 2011 at 07:06 UTC

    Hi, exactly what i am thinking is i need to fill my hash with more number of elements. now in the above code i have only one element in hash so its displaying one key.i need to iterate all keys and vaues in my hash.can you help how can i iterate all keys in my hash.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-01-29 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (74 votes). Check out past polls.

    Notices?