Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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.

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.


Comment on Re: Little annoying mistakes ... of others
Select or Download Code
Re^2: Little annoying mistakes ... of others
by GrandFather (Cardinal) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-08-20 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (107 votes), past polls