Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Looking for some assistance in cleaning up a perl script

by rev_1318 (Chaplain)
on Jun 22, 2011 at 18:53 UTC ( [id://910963]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://910963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found