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.

Replies are listed 'Best First'.
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.