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
sub mycode { (my $var = $_[0]); (defined($var) ? print("mycode() called with $var\n") : print("mycode() called with no operands.\n")); ($var and (my $foo = 'blah')); #^^^^^^^^^^^^^^^ Look here ($foo and print("foo is $foo\n")); ($foo ||= 'FOO'); } mycode('test'); mycode(); mycode(); mycode(); a.pl syntax OK
my $foo = 'blah' is optimized away.
In order to make it behave as expected, my $foo; needs to be its own statement, with no conditional.
Update: Removed bit about strict, see the follow up
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: static-like persistence of my variable due to trailing conditional
by meonkeys (Chaplain) on Jun 29, 2002 at 22:52 UTC | |
by jsprat (Curate) on Jun 29, 2002 at 23:32 UTC | |
by Aristotle (Chancellor) on Jun 30, 2002 at 17:35 UTC |