Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Recursive loops

by dsheroh (Parson)
on Dec 11, 2012 at 08:38 UTC ( #1008241=note: print w/ replies, xml ) Need Help??


in reply to Recursive loops

Why jump to recursion? I don't see any reason for it in your post. Personally, I'd use a queue for this:

my @queue = (1, 2, 3, 4); while (@queue) { my $current = shift @queue; next unless subA($current); push @queue, subB($current); }
(And don't get in the habit of prefixing your sub calls with &. It's not required in Perl 5+ and has side-effects that you probably don't expect.)


Comment on Re: Recursive loops
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (16)
As of 2015-07-07 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls