in reply to Re^2: scope of variable
in thread scope of variable
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: scope of variable
by BrowserUk (Patriarch) on May 27, 2013 at 12:44 UTC | |
Forgot to mentioned, I have use strict; You should also be using warnings (or -w) because then you would see:
And resolving those would go a long way to explaining the problem you describe in the OP. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
|
Re^4: scope of variable
by hdb (Monsignor) on May 27, 2013 at 12:40 UTC | |
bart's comment on closures is exactly the reason for your problem. See this simplified example:
which creates the following output (including a couple of warnings!):
which clearly demonstrates that the variable $strange in the subfuncs is decoupled from $strange in func in the second and subsequent calls to func. The warnings also tell the same story. UPDATE: Compare to the following:
whose output is probably what you expected. Whether or not this is good style is a diffent question ... | [reply] [d/l] [select] |