in reply to Ouch! Each! Reentrant it is not
That's a nice demonstration of remembered state with each. It can be a useful property to exploit for some kinds of iterators, but it's pretty fragile. As you say, calling keys on the hash resets the each state.
You can avoid the scalar op and a useless variable by just calling keys in scalar context:
keys %hash and return "The key for 2 is $key\n" if $val == 2;
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ouch! Each! Reentrant it is not
by Thilosophy (Curate) on Jul 15, 2005 at 03:01 UTC | |
|
Re^2: Ouch! Each! Reentrant it is not
by greenFox (Vicar) on Jul 15, 2005 at 03:04 UTC |