in reply to What is the difference between 'local' and 'my'?
When you use 'local' in to localize a variable, what is really happening is that Perl will store the value of any variable that already has the localized variables name when the localized variable is initialized. When the sub-routine ends and the program returns to the main body, Perl will restore the old value of the original variable. Ex:
The output from this program would be:$a = "one"; print $a, "\n"; routine(); print $a, "\n"; sub routine { local $a = "two"; print $a, "\n"; }
-kelone two one
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Answer: What is the difference between 'local' and 'my'?
by goldclaw (Scribe) on Jan 25, 2001 at 01:38 UTC |
In Section
Seekers of Perl Wisdom