in reply to Re: Resetting variables
in thread Resetting variables
A lot of folks have wagged fingers at me for using global variables, and I know what they mean. I just don't know how else to do it! If I want to have a variable that needs to be accessed/updated by the main loop and by multiple subs...how can you do that without storing the variable outside of all the subs? If I try to put it in the loop it will be zeroed out on every loop, and the same with the subs. Any ideas would be appreciated.
This is what I mean:
my $var = 0; while (condition) { # read var; gets changed by sub2 on occasion sub1() sub2() } sub1 { # read $var; gets changed by sub2 on occasion } sub2 { # update $var }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Resetting variables
by Sandy (Curate) on Dec 21, 2004 at 22:09 UTC | |
by yacoubean (Scribe) on Dec 21, 2004 at 22:17 UTC |