looping-over-perl-hashA lot of the time, you'll see people loop across keys in a hash like this:
foreach my $key (keys %hash) {
print "$key => " . $hash{$value} . "\n";
}
Which is not very efficient especially if %hash is very large because the "keys" call constructs a large array. Looping across all key/value pairs in a hash is best accomplished by using a while loop:
while (my ($key, $value) = each(%hash)) {
print "$key => $value\n";
}
Notes:
|
|