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.
my $x; # one statement
$x = $y if {condition;} # two statement
the perlsyn you quoted is different
my $x if ...
presuming
my $x = $y if {condition;}
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?
In my testing of this, it works (perhaps version dependent?):
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
getting strict "breaks" the behavior,
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
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.
??
Be Appropriate && Follow Your Curiosity
|