in reply to hash iteration with each
The wording of the keys() doc describing this behavior as a 'side effect' doesn't warm my heart, and leads me to believe it might be leading my down the dark road of Obfuscated Code...
Lucid comments are very helpful. Something like this can hardly be considered obfuscated:
OUTER_LOOP: foreach my $item qw(this that the_other) { print "$item:\n"; keys %hash; # keys resets the iterator on %hash so that our # subsequent calls to each will get all the # pairs in the hash. This is necessary in # case the iterator was left in mid-hash # by a previous loop-through that was aborted. while (my ($key, $value) = each %hash) { print " $key => $value\n"; if ($item eq 'that' && $key eq 'baz') { print "bailing out!\n"; next OUTER_LOOP; } } }
for(unpack("C*",'GGGG?GGGG?O__\?WccW?{GCw?Wcc{?Wcc~?Wcc{?~cc' .'W?')){$j=$_-63;++$a;for$p(0..7){$h[$p][$a]=$j%2;$j/=2}}for$ p(0..7){for$a(1..45){$_=($h[$p-1][$a])?'#':' ';print}print$/}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash iteration with each
by Aristotle (Chancellor) on Mar 16, 2003 at 01:19 UTC |