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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've been going over the posts and tutorials here on this subject, and I have made it to the point where I can code a very straightforward example of very simple recursion.
#!/usr/bin/env perl use strict; use warnings; sub recurse_factory { my $max = shift; my $number = shift; if ($number < $max) { return sub { return recurse_factory($max,$number+1); } } else { return sub { print "done ... $number\n"; }; } } my $TIMES = 100; my $next = recurse_factory(100,0); for (1..$TIMES+1) { $next = $next->(); }
However, I am trying to figure out how one may use this method (if at all) for a more complicated recursive algorithm. In essence what I'd like to do is find all acyclic paths in a digraph using the recursive depth first search method.

In otherwords, the recursion pattern looks more like the depth first traversal of a tree than a simple straight line like my simple example above. I am sure locked away in the great explanations I've found on this site is the key, but I need to be hit with a really big clue stick.

I think for this discussion, the recursive depth first traversal of a tree that returns a full root-to-leaf path would be an appropriate example...btw, I am assuming that this can be done with rgi's, but I could be wrong there, too.

TIA

In reply to Question about recursively generated iterators by perlfan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-28 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found