By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,850 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,850 IT Pros & Developers. It's quick & easy.

Iteration over Hash of Arrays

P: 1
Greetings!

Please forgive my newness to Perl, but I was hoping some of you perl data mungers would be able to help me!

given an array of hashes as follows:


Expand|Select|Wrap|Line Numbers
  1. my %adj = (
  2.             1 => [1,2,4],
  3.             2 => [1,2,3,5],
  4.             3 => [2,3,6],
  5.             4 => [1,4,5,7],
  6.             5 => [2,4,5,6,8],
  7.             6 => [3,5,6,9],
  8.             7 => [4,7,8],
  9.             8 => [5,7,8,9],
  10.             9 => [6,8,9]
  11.             );
how does one go about iterating over all of the array elements?

Thanks in advance
Mar 9 '08 #1
Share this Question
Share on Google+
2 Replies


eWish
Expert 100+
P: 971
Have a look at perldsc. If you have problems post back and we will try and help you further.

--Kevin
Mar 9 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
Definetly read the link eWish posted for you. One way to loop through the data:

Expand|Select|Wrap|Line Numbers
  1. foreach my $keys (keys %adj) {
  2.    print "$keys\n";
  3.    foreach my $index ( @{$adj{$keys}} ) {
  4.       print "\t$index\n";
  5.    }
  6. }
Mar 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.