On Sat, Jun 14, 2003 at 11:33:17PM +0200, Marcin Kasperski wrote:
> Hmm, probably well known but ... I have not met any direct warning of
> this problem so far.
>
> our %SOME_CONFIG = (
> a => 1,
> b => 2,
> c => 3,
> );
>
> ...
> while (my($k,$v) = each %SOME_CONFIG) {
> if( ... ) {
> return; # or last, or throw exception
> }
> }
>
> You probably see the problem - when this code is re-executed (next
> request), the loop iterates just over 'the rest' of the hash.
>
> Does there exist some way to protect before this problem (some kind of
> auto-destructor, finally, whatever which would automatically rewind
> the hash internal iterator while leaving the context)?
Not really a mod_perl problem, but you can read about the solution in
the docs for each.
There is a single iterator for each hash, shared by all "each",
"keys", and "values" function calls in the program; it can be reset
by reading all the elements from the hash, or by evaluating "keys
HASH" or "values HASH".
perldoc -f each
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net