On Fri, Jul 11, 2008 at 04:49:55PM -0400, Bob Rogers wrote: Content-Description: message body text > This is certainly not the case for recursive subs. Consider the > attached example, a lightweight Perl 5 dumper. (It is slightly > artificial to break the recursive step out into a sub, but that might > make sense after adding hash support.) We need a distinct closure for > each level of dump_thing call, lest $prefix refer to the wrong thing. > And we need to call those closures from registers, to be sure that we > are calling the right one.
In the attached example, I think the lines > my $recur = sub { > my $subthing = shift; > > dump_thing($subthing, $prefix.' '); > }; guarantee that $recur gets a distinct closure for each level of call, since a closure is cloned upon assignment. In other words, the assignment is where a separate newclosure would be performed (or, in my example, simply cloning the closure directly). Pm