Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
P is for Practical
 
PerlMonks  

Re: Failing to warn about "Found = in conditional"

by ww (Chancellor)
on Apr 17, 2012 at 02:18 UTC ( #965422=note: print w/ replies, xml ) Need Help??


in reply to Failing to warn about "Found = in conditional"

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?


Comment on Re: Failing to warn about "Found = in conditional"
Select or Download Code
Re^2: Failing to warn about "Found = in conditional"
by AnomalousMonk (Prior) on Apr 17, 2012 at 02:32 UTC

    FWIW, on my Win 7 box AS Perl 5.8.9 build 827 and Strawberries 5.10.1.5, 5.12.3.0 and 5.14.2.1 all warn about assignment in a conditional.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2013-05-18 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (392 votes), past polls