in reply to Why is it uninitialized?
I believe you've inadvertantly created something akin to a closure (except it's not anonymous), and perl is using the current value (undef) of the lexical variable $S4 when the subroutine is defined. The variable needs to have package-level scope (which our $S4 gives you; aka "global") in order to be "live" in the subroutine. Or, better, pass it as a parameter to the function.
Some of this is hinted at in perlsub, search for the first instance of "closure", and perlref. You can read those statements in the docs without realizing the implications, until you actually run across a bug that helps it solidify.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is it uninitialized?
by dave_the_m (Monsignor) on Dec 20, 2017 at 18:53 UTC | |
|
Re^2: Why is it uninitialized?
by Laurent_R (Canon) on Dec 20, 2017 at 19:00 UTC | |
by pryrt (Abbot) on Dec 20, 2017 at 19:04 UTC | |
by Laurent_R (Canon) on Dec 20, 2017 at 19:49 UTC |