On Thu, 20 Mar 2003, NYIMI Jose (BMB) wrote:
> Hello,
>
> How can I do this unix command in Perl ? : ls -lrt | tail -1
> Actually, i would like to get the most recent file from a given directory.
my $latest = (sort {-M $b <=> -M $a} <$dir/*>)[-1];
or
my $latest;
while (<$dir/*>) {
$latest = (defined ($latest) && (-M $_ > -M $latest)) ? $latest : $_;
}
Remember to check for the definedness of $latest if $dir is an empty
directory
>
> Thanks in advance for your input.
>
> Jos�.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]