Yes, you can "turn off some warnings" as you ask in your first sentence, but it appears that you really want your nix box to issue one. Why it fails to do so, I can't say, but the same behavior occurs with AS Perl 5.014 sub 2 on a Win 7 box.
That seems odd, since the single equals sign is an assignment; the message you cite correctly suggests using == in the conditional. The rest is merely an expansion on dasgar's observation:
FWIW, with alternate code,
my @count = qw/1 2 3 4/;
while ( my ( $iter, $value ) = each @count ){
if ($value < 2 ) {
print "$iter: one\n";
} elsif ($value == 2) { # NO ERROR HERE, NOW
say "$iter: HA!\n";
} else {
print "$iter: three!\n";
}
}
one receives the expected values,
0: one
1: HA!
2: three!
3: three! # This is a very special case where 4 == three :-)
and restoring the single equals sign in the conditional
my @count = qw/1 2 3 4/;
while ( my ( $iter, $value ) = each @count ){
if ($value < 2 ) {
print "$iter: one\n";
} elsif ($value = 2) { # LOGICAL ERROR HERE
# assignment rather than test of equality
# but no 'plaints from Perl
print "$iter: HA!\n";
} else {
print "$iter: three!\n";
}
}
... also produces the expected (but incorrect, if I understand you correctly) sequence of output,
0: one
1: HA!
2: HA!
3: HA!
I can only guess the Perl version on your Mac is slightly better at noting the problem.
Update: Corrected typos and bad markup... but also noted that you say the Mac version cites an error at line 36. It's line 21 in the code you posted... and even allowing for a hashbang and a blank line, that doesn't match well with "36." Is there something else in the code on either machine that you didn't show us that might explain the mystery?
|