in reply to Re: Local $$_?
in thread Local $$_?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Local $$_?
by Corion (Patriarch) on Mar 15, 2010 at 11:13 UTC | |
should carry over the values, but on this 5.10.0, it exhibits inconsitent behaviour: Saving the values keeps the localizing behaviour:
"Resetting" the values destroys the localizing behaviour:
The same failure with the direct assignment:
I would consider this inconsistency a bug, but maybe it's already fixed in 5.10.1 or 5.11.
| [reply] [d/l] [select] |
by LanX (Saint) on Mar 15, 2010 at 13:42 UTC | |
I suppose the problem you're experiencing is not really a bug but due to the fact that a slice on the stash deliveres globs not values:
initializing the localized vars should be done with the _values_ not with the globs. In this way you are "re-aliasing" the package vars to the old ones! But I'm not enough of a perl4 expert for details... ;) Cheers Rolf UPDATE: to be more precise, your code above should be equivalent to something like local (*a,*b) = (*a,*b) and not local ($a,$b) = ($a,$b) | [reply] [d/l] [select] |
by Anonymous Monk on Mar 15, 2010 at 11:42 UTC | |
| [reply] |
|
Re^3: Local $$_?
by Anonymous Monk on Mar 15, 2010 at 11:14 UTC | |
I fear your reasons for doing this | [reply] [d/l] |
|
Re^3: Local $$_?
by LanX (Saint) on Mar 15, 2010 at 12:01 UTC | |
Cheers Rolf | [reply] |
by expresspotato (Beadle) on Mar 15, 2010 at 12:47 UTC | |
| [reply] |
by LanX (Saint) on Mar 15, 2010 at 12:54 UTC | |
Glad if I was able to help! :)
Cheers Rolf UPDATE: But you should do thorough testing to be sure about the side-effects! Be aware: In many cases testing and fixing resulting bugs aren't cheaper than rewriting ... Using lexical variables are almost always better! | [reply] |
by Anonymous Monk on Mar 15, 2010 at 13:03 UTC | |
All you really needed was then you copy/paste
Although it is not a perfect solution - it seems to be working. The use of global variables is red flag. Your statement that "it seems to be working" also indicates that it doesn't come with a test suite, another red flag. I think now is a time to consider/plan to refactor this program. | [reply] [d/l] [select] |
by LanX (Saint) on Mar 15, 2010 at 13:28 UTC | |
Maybe a misunderstanding, in the OP you were trying to localize package vars in a loop, this can't be done because of the loop scope. But of course you are free to initialize the vars in a loop or a list assign _after_ you localized them.
Cheers Rolf | [reply] |