in reply to Re: "if" in a my declaration statement causes problem
in thread "if" in a my declaration statement causes problem
My dense skull isn't penetrating this issue. The original poster wrote ...
Update: No, the original poster did not write what I claimed. The first response did.
the perlsyn you quoted is differentmy $x; # one statement $x = $y if {condition;} # two statement
in his case. These seem to be different. You are holding up the perlsyn snip as an example says the two cases are synonyms. Why?my $x if ... presuming my $x = $y if {condition;}
In my testing of this, it works (perhaps version dependent?):
getting strict "breaks" the behavior,sunorccws04 ~$ cat tpl ; ./tpl #!/usr/bin/perl sub showme; foreach $y ( 1..10) { $foo = $y; print showme(), "is the x value\n"; } sub showme { my $x; $x = $y if ($foo %2); # might as well mix up some T/F } 1 is the x value 0 is the x value 3 is the x value 0 is the x value 5 is the x value 0 is the x value 7 is the x value 0 is the x value 9 is the x value 0 is the x value
predefining x as in my $x = 0;, doesn't change the results. Changing the declaration of $y, $foo from my to our causes the code to behave like the non-strict version. But in all cases the results are consistant and predictable.sunorccws04 ~$ cat tpl ; ./tpl #!/usr/bin/perl use strict; my ($foo, $y); sub showme; foreach $y ( 1..10) { $foo = $y; print showme(), " is the x value\n"; } sub showme { my $x; $x = $y if ($foo %2); # might as well mix up some T/F } is the x value 0 is the x value is the x value 0 is the x value is the x value 0 is the x value is the x value 0 is the x value is the x value 0 is the x value
??
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: "if" in a my declaration statement causes problem
by ysth (Canon) on Feb 22, 2006 at 19:15 UTC |