bigmoose has asked for the wisdom of the Perl Monks concerning the following question:
Hi Everyone
If I have some code where I want to call a sub routine and increase a variable within it each time I call it, how would I do that?
So for example... the below is how i tought it would work.. pseudo code style!..
run = 1 while (run == '1') { print increaseNumber(); } sub increaseNumber { my $value = 001 return $value + 1 }; ###which would print### 001 002 003 ###etc###
feel like im struggling because i'm not aware of a concept.. please help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: increasing value every time sub routine called
by BrowserUk (Patriarch) on Dec 09, 2011 at 12:39 UTC | |
by bigmoose (Acolyte) on Dec 09, 2011 at 12:49 UTC | |
|
Re: increasing value every time sub routine called
by Fox (Pilgrim) on Dec 09, 2011 at 12:48 UTC | |
|
Re: increasing value every time sub routine called
by johngg (Canon) on Dec 09, 2011 at 16:22 UTC | |
|
Re: increasing value every time sub routine called
by jethro (Monsignor) on Dec 09, 2011 at 12:56 UTC | |
by JavaFan (Canon) on Dec 09, 2011 at 14:07 UTC | |
by dave_the_m (Monsignor) on Dec 09, 2011 at 15:33 UTC | |
by JavaFan (Canon) on Dec 09, 2011 at 21:50 UTC | |
|
Re: increasing value every time sub routine called
by TJPride (Pilgrim) on Dec 09, 2011 at 19:16 UTC |