so if I showed @test, would I get 1 5 3 4 6 7?All you have to do is print it to see:
Outside of the sub, @i is undefined because of the scope.use warnings; use strict; use Data::Dumper; sub simpleTest { my @i = qw(1 5 3 4 6 7); return @i; } my @test; @test = simpleTest(); print '@test: ', Dumper(\@test); __END__ @test: $VAR1 = [ '1', '5', '3', '4', '6', '7' ];
For recursion, you could use state:
See also: How do I compose an effective node title?use warnings; use strict; use feature "state"; testFunc(); sub testFunc { state $i = 0; $i++; print "i=$i\n"; testFunc() if $i < 4; } __END__ i=1 i=2 i=3 i=4
In reply to Re: value of returned array, and remember variable in recursive function
by toolic
in thread value of returned array, and remember variable in recursive function
by The Elite Noob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |