To continue on wazat's post, use substr and eq instead of regexs for such ridiculously simple patterns. It will be faster.
my $file_time = (stat($full_name))[9];
my $diff = $now - $file_time;
$diff = $diff / 86400;
my $read = localtime($file_time);
combine statements 1, 2, and 3. Something like
my $file_time;
my $diff = ($now - ($file_time = (stat($full_name))[9])) / 86400;
my $read = localtime($file_time);
less assignments/reads and less pp_nextstate ops.
$diff = $diff / 86400;
my $read = localtime($file_time);
if ( $diff > 93 ) {
print FILE "$full_name : $diff : $read\n";
unlink "$full_name";
} elsif ( $diff > 3 ) {
next if (/\.gz/);
Optimize out the division by multiplying 93 and 3 by 86400, and comparing to the larger numbers than doing the division. And substr/eq instead of the .gz regex.
unlink "$full_name";
That looks bizzare like someone who has never done Perl before, don't do that.
my $read = localtime($file_time);
Don't do that, don't print the converted time to console, just the unix time. If someone really wants read the log they can do the conversion themselves.
IDK if you can do it with stat() or not, but get the -f and -d and stat on $full_name into exactly ONE syscall, save results to lexicals, then process the results. Don't do redundant I/O calls.
I would guess if you used Nytprof (you should have used that BEFORE coming to perlmonks), your script is either I/O bound to disk/filing system or CPU bound in gzip compression algoritm.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.