in reply to Return newest file
You can get the last file in one go.
$last= (sort { -M $b <=> -M $a } <*.log>)[-1];
If you have a very large number of files, you may consider using the Schwartzian Transform to minimize sorting time.
$last = ( map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_, -M $_ ] } <*.log> )[-1];
Both versions are short enough to be used in a one-liner.
Update
Tested in Linux and Windows. Works fine.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Return newest file
by snax (Hermit) on Aug 13, 2003 at 20:29 UTC |