Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Answer: How do I make a hash of arrays?

( #352421=categorized answer: print w/ replies, xml ) Need Help??

Q&A > Data Structures > How do I make a hash of arrays? contributed by Doraemon

my $array = []; #create new anonymous array ref push (@$array, '11'); push (@$array, '12'); push (@$array, '13'); $hash{'first'} = $array; # add $array = []; #create a new anon-array push (@$array, '21'); push (@$array, '22'); push (@$array, '23'); $hash{'second'} = $array; # add print "Hash content\n"; foreach $k (keys %hash) { foreach (@{$hash{$k}}) { print " : $_"; } print "\n"; }

Comment on Answer: How do I make a hash of arrays?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-07-11 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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








    Results (217 votes), past polls