in reply to 'each' syntax oddity?
One other side effect of the single iterator is that you can't use nested each loops on the same hash. Try this:
Hint: Make sure you're near the break/interrupt key.use strict; my %hash = (FOO => 'foo', BAR => 'bar', FUBAR => 'fubar'); my ($key1, $val1); my ($key2, $val2); while (($key1, $val1) = each %hash) { print "OUTER: $key1=$val1\n"; while (($key2, $val2) = each %hash) { print " INNER: $key2=$val2\n"; } }
This bit me once where a not-so-good design had me iterating through the same hash nested, but pretty far apart so it wasn't obvious. Imagine that the inner loop above is really several calls away in another package and you get the idea.
|
|---|