in reply to Making a variable in a sub retain its value between calls
That's the way to do it in Perl, but one note of caution: your initializer isn't being executed before your loop. The declaration and sub definition happen at compile time, but the assignment is a runtime thing, and the code gets run from top to bottom. Your output is unchanged even if you initialize $memory to 'a' (which the autoincrement op should then change to b and c in turn).
Caution: Contents may have been coded under pressure.
You can make your enclosing block a BEGIN block, or you can put it above the rest of your code.
Caution: Contents may have been coded under pressure.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Making a variable in a sub retain its value between calls
by tlm (Prior) on Apr 18, 2005 at 21:50 UTC | |
by ihb (Deacon) on Apr 18, 2005 at 23:41 UTC | |
by tlm (Prior) on Apr 19, 2005 at 00:11 UTC | |
by ihb (Deacon) on Apr 19, 2005 at 00:24 UTC | |
by tlm (Prior) on Apr 19, 2005 at 00:36 UTC | |
| |
by ihb (Deacon) on Apr 19, 2005 at 16:24 UTC | |
Re^2: Making a variable in a sub retain its value between calls
by crashtest (Curate) on Apr 19, 2005 at 16:39 UTC |
In Section
Seekers of Perl Wisdom