Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Return newest file

by chromatic (Archbishop)
on Aug 13, 2003 at 06:16 UTC ( [id://283464]=note: print w/replies, xml ) Need Help??


in reply to Return newest file

You can access items in an array with negative indices:

my @list = `dir *.log \/B \/OD`; my $newest = $list[-1]; print "$newest\n";

Some people dislike shelling out, though. You could use readdir, sort, and the -X filetest operators to check timestamps. I think it'd look something like this:

my @files = sort { -M $a <=> -M $b } <*.log>; my $newest = $files[-1]; print "$newest\n";

That's untested, though, since it's late and I don't run Windows.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-16 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found