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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.