in reply to Foreach syntax
Any time you find yourself looking up a hash value for each key of a hash, don't forget the appropriately named each function.
while (my ($p9, $is_available) = each %is_available) { next if !$is_available; # do something with each available $p9 }
The foreach (keys) iteration walks through the hash but averts its eyes from the values. The while (($key, $value) = each) iteration sensibly says we may as well grab the value while we're in the neighborhood.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Foreach syntax - don't forget the each function!
by FunkyMonk (Bishop) on Jul 25, 2008 at 22:21 UTC |