Wednesday, September 9, 2009

how to iterate through a hash in Perl

Yes, I'm a Perl newb. And I really don't like Perl much. But I still have to read through Perl code and sometimes modify it. So here's how a bit of Perl 101 for myself.
Here's how to iterate through a hash in Perl:


foreach my $key (keys %myhash)
{
print "key: $key value: $myhash{$key}\n";
}


I like this construct because it's pretty clear what's happening.

Ad: Learning Perl, 5th Edition

No comments: