The Elite Noob has asked for the wisdom of the Perl Monks concerning the following question:
1. Return for arrays in Perl Ok first question. Say, you have this code.
Lets assume this code works and is bug free. Now, would the value of @test be @i? so if I showed @test, would I get 1 5 3 4 6 7?... sub simpleTest{ ... my @i = qw(1 5 3 4 6 7); return @i; } my @test; @test = simpleTest();
1. Next, how do you get a recursive function to remember the value of a variable? so if you have this.
In this code how do you get $i to keep increasing by one every time its called? so instead of this. 0 1 0 1 it prints 1 2 3 4 5 6 7 8 9. Thanks! For your help! I appreciate it!sub testFunc{ my $i = 0; $i++; testFunc(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: value of returned array, and remember variable in recursive function
by toolic (Bishop) on Mar 01, 2011 at 23:25 UTC | |
by The Elite Noob (Sexton) on Mar 01, 2011 at 23:58 UTC | |
|
Remembering the value of a variable
by ig (Vicar) on Mar 02, 2011 at 05:49 UTC |