Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Scoping problems with recursive function

by fullermd (Priest)
on Mar 19, 2010 at 18:14 UTC ( #829670=note: print w/replies, xml ) Need Help??


in reply to Scoping problems with recursive function

It is as if the "each" somehow is like a "global" in that when I call the function recursively, it remembers at which value it was at and continues from there.

It is. Or rather, it's tied to the hash, so that it will always pick up where it left off anywhere. See 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".

You probably want to use keys instead to iterate over it:

for my $key (keys %hash) {

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2020-11-27 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?