Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Nested Loops vs Good programming

by snopal (Pilgrim)
on Nov 14, 2008 at 14:09 UTC ( [id://723656]=note: print w/replies, xml ) Need Help??


in reply to Nested Loops vs Good programming

Recursion is your friend. By understanding both scoped variables and how to package and pass your current values forward in the recursive call, you can have both your current virtually unlimited level, and all previously detected superior values at any moment in time.

Be aware that recursion is memory intensive, so this ability gives you extreme flexibility, at several costs. First, it becomes a memory hog for depth-wise structures which may leave you "out of memory". Second, you still have the reponsibility to eventually leave the recursion in an orderly fashion (usually by return at the end of each level).

It is not good practice to step out of recursion before unwrapping all the depth you have accumulated. It is better to pass out your constructed structure or build an external structure if you need values outside the recursion.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-24 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found