Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: problem using foreach and each with hash ref

by sanku (Beadle)
on Aug 21, 2009 at 12:34 UTC ( #790349=note: print w/ replies, xml ) Need Help??


in reply to problem using foreach and each with hash ref

hi, I think it's not that much easy to both key and value pair for hash but you can get either key or value. In my code i used the keys indexes to get the values of hash reference.

use strict; use warnings; use Data::Dumper; my $hash_ref={1002=>[1,2,3,4,5],1001=>[6,7,8,9,10],3=>[2]}; my ($hashref,$array_ref,@array,); foreach $hashref( keys %$hash_ref){ $array_ref=$$hash_ref{$hashref}; @array=@$array_ref; print "Key = ".$hashref."\tValue = "; foreach (@array){ print "$_ \t"; } print "\n"; }


Comment on Re: problem using foreach and each with hash ref
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-07-13 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls