in reply to how subroutine functions when declare "my" twice in main

The $s in the sub is a closure to the last declaration of $s before the sub was compiled.

So when you call it at runtime before it was initialized it's of course undefined.

(my does declaration at compile time and initialization at run time)

Sorry if I don't elaborate more on "broken" code, just don't do this ... there is a reason why you get warnings! :)

Cheers Rolf

( addicted to the Perl Programming Language)

  • Comment on Re: how subroutine functions when declare "my" twice in main

Replies are listed 'Best First'.
Re^2: how subroutine functions when declare "my" twice in main
by Anonymous Monk on Nov 05, 2013 at 19:36 UTC
    Thanks much.