in reply to Looking for some assistance in cleaning up a perl script

No need to use pastbin. You can add your code here just fine using code-tags (and readmore-tags)...

Some first comments:

use variable names which mean something, also to others :)

use consistent indentation in your code to improve readability

use lexical file and directory handles

this:

# Sorts files in $dir and sets $latest->{file} with newest file. my $latest = (sort {$b->{mtime} <=> $a->{mtime}} map {{mtime => -M $_, file => $_}} <$dir/*>)[-1]; my $newM = (stat $latest->{file})[9]; # Sorts files in $dir and sets $oldest->{file} with oldest file. my $oldest = (sort {$a->{mtime} <=> $b->{mtime}} map {{mtime => -M $_, file => $_}} <$dir/*>)[-1]; my $oldM = (stat $oldest->{file})[9];
to determine the oldest and newest file, could easier be writen as:
my ($newM, $oldM) = (sort {-M $a <=> -M $b} <./*>)[0,-1];
No need for maps etc. (oh, and better use glob...)

HTH,

Paul

Replies are listed 'Best First'.
Re^2: Looking for some assistance in cleaning up a perl script
by shadowfox (Beadle) on Jun 22, 2011 at 21:43 UTC

    Thanks for the tip about the code tags, I ignorantly used [code][/code] to start with and it didn't work so I pastbined it here to avoid cluttering the front page. Good call on the readmore tags though, it made me realize the tag syntax I was using was the problem, I should have investigated it further.

    Anyway, I shorted it down to the part of concern, there probably isn't much that can be improved to the smtp email sending and logging so I took it out from the example. Thanks for the comments so far, I'll make some reflected changes tomorrow and report back with an update.