in reply to Re: Re: static-like persistence of my variable due to trailing conditional
in thread static-like persistence of my variable due to trailing conditional
So when you call mycode() with no arguments then my $foo = 'blah' is not executed at all. Instead, simply $foo = 'FOO' gets executed, setting $main::foo (you can verify this by printing out $main::foo after you call mycode() with no arguments).
use strict is only supposed to catch compile-time errors (according to its documentation). It should not blow up at runtime.
To do what you expect here you could do something like:
my $foo = defined $var ? 'blah' : 'FOO';
or even:
my $foo;
if ($var) {
$foo = 'blah';
}
else {
$foo = 'FOO';
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: static-like persistence of my variable due to trailing conditional
by Aristotle (Chancellor) on Jun 30, 2002 at 17:45 UTC | |
|
Re: Re: Re: Re: static-like persistence of my variable due to trailing conditional
by meonkeys (Chaplain) on Jun 30, 2002 at 17:17 UTC |