in reply to subroutine recursion question
Clear it before calling walk.
foreach my $r (@array){ my @big; walk($r); ... } sub walk { my $i = shift; push @big, $i; for (@{$hash{$i}}){ walk($_) } }
However, it's bad practice for a sub to modify some private variable somewhere. Fix:
orforeach my $r (@array){ my @big; walk(\@big, $r); ... } sub walk { my $big = shift; my $i = shift; push @$big, $i; for (@{$hash{$i}}){ walk($big, $_) } }
foreach my $r (@array){ my @big = walk($r); ... } sub walk { my $i = shift; my @big = $i; for (@{$hash{$i}}){ push @big, walk($_); } return @big; }
|
|---|