"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, $_ ); } 6) There's a trailing 0; which A) does nothing, B) is misleading because "1;" means success for modules. (Cleaner) 7) 8) Assigning to $_ is very dangerous without using local $_ first. In reply to Re: Pls help optomize - ksh version 60% faster!
by ikegami
|
|