in reply to Conditional initialization of lexical (my) variables
I am not sure why you would expect any other behavior?
If the "unless" condition results in the "my my_var" not executing, then 'my_var' is never declared in the scope of the subroutine.
So when the next line assigns to 'my_var' - the assignment is done to a global variable.
So it is not persisting across calls, its just not scoped to the subroutine, but your entire file.
I always thought it was perfectly logical code, and I had used it in some situations as a convenient form of name overloading. Alas it looks like this caught out so many people they made it an error, and now people even claim it was a bug all along... which is nonsense.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Conditional initialization of lexical (my) variables
by ikegami (Patriarch) on May 11, 2023 at 08:35 UTC | |
|
Re^2: Conditional initialization of lexical (my) variables
by LanX (Saint) on May 11, 2023 at 07:57 UTC |