Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Ouch! Each! Reentrant it is not

by truedfx (Monk)
on Jul 15, 2005 at 19:36 UTC ( [id://475341]=note: print w/replies, xml ) Need Help??


in reply to Re: Ouch! Each! Reentrant it is not
in thread Ouch! Each! Reentrant it is not

Localising does give you a local iterator. Try this code:
%a = ( A=>0, B=>1, C=>2 ); %b = %a; print each %b, "\n"; { local %b = %a; each %b; } while(($k,$v)=each %b) { print $k, $v, "\n" }
Then, try this:
%h = ( A=>0, B=>1, C=>2 ); print each %h, "\n"; () = %h; print each %h, "\n";
The problem with local %h = %h is not that the local copy shares the iterator, but that the original %h gets its iterator reset by being read. This is mentioned briefly in the documentation for the each function.

Replies are listed 'Best First'.
Re^3: Ouch! Each! Reentrant it is not
by BrowserUk (Patriarch) on Jul 15, 2005 at 20:31 UTC

    Hmmm. So you would have to localise and copy before using the outer level iterator in order to preserve it across a (possible) inner level iterator? Not very useful.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://475341]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found