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:
to determine the oldest and newest file, could easier be writen as:# 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];
No need for maps etc. (oh, and better use glob...) HTH,my ($newM, $oldM) = (sort {-M $a <=> -M $b} <./*>)[0,-1];
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 |