http://qs321.pair.com?node_id=728591


in reply to Little annoying mistakes ... of others

As part of my job, I review code by people that are less then experienced with Perl. I've seen some bad code such as:
open(F, "grep 'WARNING<\/font>' $mydir/$myfile".".|wc|awk '{print \$1} +'| ") ; while (<F>) { chomp(); $received_warn=$_; } close F;

Which is part of a larger script where the same file was opened and closed several times and processed as shown by scanning the entire file, looking for specific html, then counting rows in the output file for the condition. Meanwhile, all of the information needed for all of the processing was available from a single pass of the file head.

However, I think the most common mistake people make is confusing numeric comparisons with string comparisons. This kind of mistake often passes simple manual tests but breaks if it gets to production.

Example:
$a = 'a'; if ($a == 'b' or $a == 'c') { print "True\n"; }
...or even worse:
if ($a = 'b') { print "True\n"; }
Both examples print 'True', but the last example has corrupted your data.