[OT] Perl woes

Chris Jack chris_jack at msn.com
Wed Jan 28 13:54:47 GMT 2009


>> <dominic.thoreau at googlemail.com> wrote:>> $ perl -le 'print "yes" if "a" == "2"'>> $ perl -le 'print "yes" if "a" == "a"'>> yes>> $ perl -le 'print "yes" if "1" == "1"'>> yes>> $ perl -le 'print "yes" if "1" == "0"'>> $ perl -le 'print "yes" if "1" == 1'>> yes>> $>>>> Can you give an example where perl is doing something surprising to youI have always considered:
 
% perl -le 'print "yes" if "0"'
% perl -le 'print "yes" if " "'
yes
 
to be, if not surprising (because it's well documented), undesirable to the point of deprecating the use of "if" clauses without operators altogether. If you mean "if ($a == 0)" - you should say so. If you mean "if ($a eq '')" or "if ($a =~ /^\s*$/)" - you should say that instead. It is perl being inappropriately helpful and creating potentially subtle and occasional bugs.
 
 
Bit like one of C's conventions of allowing 0 to mean success so you constantly put "!" before functions to test for success. Of course C also has the advantage of also having a convention of allowing a negative number to mean success to avoid that horrible thing called consistency ;-)
 
 
Chris
_________________________________________________________________
Check out the new and improved services from Windows Live. Learn more! 
http://clk.atdmt.com/UKM/go/132630768/direct/01/


More information about the london.pm mailing list