On 4/18/07, yitzle <[EMAIL PROTECTED]> wrote:
I got an array of hashes so I am using a foreach (@arr) loop to access
the hashes.
How do I go about looping through the hash's keys/values? I was
thinking of another foreach, but then the $_ gets a bit screwed up...

Do I need to do this ?
foreach(@arr) {
  %hash = %{$_};
  foreach (keys %hash) {
    print "$_ => $hash{$_}\n";
  }
}

foreach is dead, long live for.

Use named values in your for loop:

for my $h (@arr) {
   for my $key (sort keys %$h) {
       print "$key = $h->{$key}\n"
   }
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to