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.
In reply to Re: Foreach syntax - don't forget the each function!
by Narveson
in thread Foreach syntax
by JimSki
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |