in reply to subroutine recursion question
my @big = gather { walk() } for @big -> $b { ... } sub walk { # do stuff here; take $result; walk(); # recurse into self }
The take is dynamically scoped, so you can call it in a different sub, in a recursive sub etc. Additionally it has the benefit of returning a lazy list, which means that the computation is only carried out if the data is really needed.
I imperfectly back-ported that behaviour to perl 5 with the module Perl6::GatherTake.
|
|---|