Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Avoiding the == blues

by BrowserUk (Patriarch)
on Dec 29, 2004 at 19:41 UTC ( [id://418062]=note: print w/replies, xml ) Need Help??


in reply to Avoiding the == blues

Even easier, use warnings or -w:

>perl -w my $splort; if( $splort = 0 ) { print 'narf!'; } ^Z Found = in conditional, should be == at - line 2.

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

Replies are listed 'Best First'.
Re^2: Avoiding the == blues (!trivial)
by tye (Sage) on Dec 29, 2004 at 19:59 UTC

    That is not nearly as useful as it only catches trivial cases:

    > perl -w use strict; my $bool = 0; if( $bool = 0 ) { print "never\n"; } <EOF> Found = in conditional, should be == at - line 3. > perl -w use strict; my $bool = 0; sub test { return 0 == @ARGV } if( $bool = test() ) { print "Match\n"; } <EOF> Match

    - tye        

Re^2: Avoiding the == blues
by friedo (Prior) on Dec 29, 2004 at 20:00 UTC
    You are absolutely correct, of course, but this doesn't work for other languages, or for badly written scripts which generate thousands of warnings that you have to maintain. :)
      In some other languages, if takes a boolean, which is (deliberately) not what an assignment returns, so if (x = 0) doesn't get past the compiler.
      Well, saying "other languages" isn't quite correct, as it's the compiler that will issue a warning, if any. And gcc with -Wall will. It will even catch cases like:
      if (x = y)
      unlike Perls -w, which will let you do
      if ($x = $y)
      while keeping silent.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-26 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found