You're missing my point, comment it out and see what happens. | [reply] |
my has both compile-time and run-time effects. See Abigail's comment in Unusual Closure Behaviour, though that's not directly related to your problem. [and damn those spelling variations]
When the my line is commented out, I suspect that Perl is not complaining about the missing declaration because of the compile-time effect, even though the line is never executed.
-QM
--
Quantum Mechanics: The dreams stuff is made of
| [reply] [d/l] [select] |
| [reply] |
I agree the behavior is strange. It seems that Perl is processing the declaration at compile-time, which is why the variable exists when the sub is declared, but isn't processing the assignment until that line is reached in runtime, which never happens.
Perhaps you've touched on an area where the right thing to do is ambiguous, so Perl's idea of what to do differs from yours.
Several people have already shown you ways to make this work, by making sure the my statement precedes the call to test in both compile- and run-time.
| [reply] [d/l] [select] |