NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
use warnings (Score:1)
$ perl -we '$a = 0; if ($a = 1) {print "a == 1!\n" }'Found = in conditional, should be == at -e line 1.
a == 1!
Granted, it's not normally a fatal error like the one you get by reversing the if, but in my opinion it is enough, and you don't need to resort to the reversal that many people find less readable. (Also, I haven't made that particular mistake in years--I do other kinds of mistakes
Re:use warnings (Score:1)
"use warnings" will however not catch the other scenario, which n1vux mentions, when you have
while ($a = 3) { }turn into an infinite loop. Nor will it catch
if ($a = my_sub()) { }(and good thing too). Having said that, I'm puzzled, what is considered to be strange about this formatting? The parentheses around the condition?
Reply to This
Parent
Re:use warnings (Score:1)
$ perl -we '$a=0; while($a=3){}'Found = in conditional, should be == at -e line 1.
But not in the second, so good catch!
"what is considered to be strange about this formatting?"
I'm sure you can get used to it after using it for a while, but there are some of us who like to read from left to right, and place the important things at the beginning of the "sentence" (this may depend on your native language, of course). I see this as a question about $a, not about 3, so I'd rather p