Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This code is a good example of the axiom: "It's possible to write FORTRAN in any lanaguge."

There are many many cases of external processes being launched to perform tasks Perl can do natively. (date, rm, cat).

Regular expressions are incorrectly used: Special characters are not escaped when they should be, and they are recompiled needlessly. Almost everywhere in the above, index should probably be used instead of regular expressions.

I'm questioning the use of so much nesting. And on the ineffciency of doing expensive operations (such as compiling regexps and using sorts) at deep levels.

Some examples:

1) Unescaped variable in $logEntry =~ /^ $date/ should be $logEntry =~ /^ \Q$date\E/ (Safer) or index($logEntry, " $date") >= 0 (Safer, Faster).

2) chmod (for the -f) followed by unlink can replace system("/usr/bin/rm -f ...");. (Safer, Faster)

3) The use of a temp file can be replaced with open(HANDLE, "|..."). (Cleaner)

4) There's even a useless use of cat. (Faster, Cleaner)

5) my @entries; while (<INIFILE>) { push(@entries, $_ ); }
can be simplified to
my @entries = <INIFILE>;
(Faster, Cleaner)

6) There's a trailing 0; which A) does nothing, B) is misleading because "1;" means success for modules. (Cleaner)

7)
for (my $i = 0; $i < 24; $i++)
is much less readable than
for my $i (0..23)
(Cleaner)

8) Assigning to $_ is very dangerous without using local $_ first.
$_ = $typeHour; /.../
can be replaced with
local $_ = $typeHour; /.../
or just
$typeHour =~ /.../
(Safer, Cleaner)


In reply to Re: Pls help optomize - ksh version 60% faster! by ikegami
in thread Pls help optomize - ksh version 60% faster! by coreolyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found