Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: recursive anonymous subroutines

by ambrus (Abbot)
on Apr 06, 2006 at 20:11 UTC ( #541716=note: print w/ replies, xml ) Need Help??


in reply to recursive anonymous subroutines

No. A code reference is the only way to use an anonymous subroutine.

Here's an example of a recursive anonymous sub from a code I wrote earlier:

# WRONG ... my $traverse; $traverse = sub { my(@c, $c, @m); @c = $_[0]; while (@c) { $c = pop @c; for (@{$member{$c}}) { push @m, $_; } for (@{$child{$c}}) { push @c, $_; } } @m; }; for (keys(%cut)) { my @m = &$traverse($_); my @m0 = grep { !$poison{$_} } @m; my @m1 = grep { $poison{$_} } @m; print "( ", jointab(@m0), "@ ", jointab(@m1), ")\n"; } ...

Update: as jdporter has noticed, this example isn't recursive. It uses a stack. I was mislead by the name "traverse". Sorry.


Comment on Re: recursive anonymous subroutines
Download Code
Re^2: recursive anonymous subroutines
by Daryn (Sexton) on Apr 06, 2006 at 20:58 UTC
    well the answers came even before I was able to update the original very incomplete post (first posting syndrome I guess). Many thanks to all.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-07-04 10:44 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 (59 votes), past polls