in reply to Basic mod-perl question : why my variable is undefined ?
It's easy to manufacture example code that shows something like the behavior you report:
This simple example code always produces the output shown. It's easy to imagine that in your "much more complex" code different execution paths are sometimes taken, such that your equivalent of $x has, on occasion, already been initialized when subroutine S() is called at point 'A'. In any event, I hope it is clear why $x is uninitialized at point 'A' and initialized at point 'B'.c:\@Work\Perl\monks>perl -wMstrict -le "my $x; ;; S('A'); ;; $x = 'foo'; ;; S('B'); ;; sub S { print qq{$_[0]: x is }, defined $x ? qq{'$x'} : 'undefined'; +} " A: x is undefined B: x is 'foo'
Update: See also the discussion in response to subroutine no error.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Basic mod-perl question : why my variable is undefined ?
by pcouderc (Monk) on Jul 23, 2014 at 14:44 UTC |