throop has asked for the wisdom of the Perl Monks concerning the following question:
I was iterating over a hash:
%foo has 56 keys, but the loop starts over again after the 3rd iteration. OK, code somewhere down in drawSomethingPretty must be performing a keys %foo and resetting my iteration. I started to rewrite aswhile (my ($key,$val) = each(%some::very::long::named::module::foo)){ if(testconditions($key)){ some::very::long::named::module::drawSomethingPretty($val)}}
but I didn't like how it looked. Is there a succinct yet readable way still use each, but not be vulnerable to being reset?my($val); foreach my $key (keys %some::very::long::named::module::foo){ $val = $some::very::long::named::module::foo{$key}; if(testconditions($key)){ some::very::long::named::module::drawSomethingPretty($val)}}
throop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Being impervious to an 'each' reset
by Util (Priest) on Dec 14, 2006 at 06:15 UTC | |
|
Re: Being impervious to an 'each' reset
by SheridanCat (Pilgrim) on Dec 13, 2006 at 23:47 UTC | |
by duckyd (Hermit) on Dec 14, 2006 at 00:15 UTC | |
by Fletch (Bishop) on Dec 14, 2006 at 00:27 UTC | |
|
Re: Being impervious to an 'each' reset
by ikegami (Patriarch) on Dec 15, 2006 at 00:35 UTC | |
|
Re: Being impervious to an 'each' reset
by Limbic~Region (Chancellor) on Dec 14, 2006 at 13:32 UTC | |
|
Re: Being impervious to an 'each' reset
by webfiend (Vicar) on Dec 15, 2006 at 00:04 UTC |