Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Little annoying mistakes ... of others

by tprocter (Sexton)
on Dec 06, 2008 at 19:41 UTC ( #728591=note: print w/replies, xml ) Need Help??

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.

$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.

Replies are listed 'Best First'.
Re^2: Little annoying mistakes ... of others
by GrandFather (Saint) on Dec 06, 2008 at 21:08 UTC

    It looks to me like the thing most of the people you are complaining about forget to always use strictures (use strict; use warnings; - see The strictures, according to Seuss).

    They should also learn not to use $a and $b in general use ($foo and $bar are good for example code).

    Learning to use the three parameter form of open, lexical variables for file handles and checking the result of the open would seem to be a higher level of sophistication. However using comprehensible and consistent indentation should be attainable for them, even if just by using Perl tidy.

    Perl's payment curve coincides with its learning curve.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-05-28 10:50 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (99 votes). Check out past polls.