Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

most recent file in a directory

Status
Not open for further replies.

columb

IS-IT--Management
Joined
Feb 5, 2004
Messages
1,231
Location
EU
I want to compare the output from a report with the output of the previous one. To do this I need to identify the most recent file in the report directory. I could, of course, do something like
Code:
my $lastlog = `ls -t $logdir|head -1`;
but I would like to do it without resorting to the system call.

Any ideas?

Ceci n'est pas une signature
Columb Healy
 
The following would work:

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$lastlog[/blue] = [red]([/red][url=http://perldoc.perl.org/functions/sort.html][black][b]sort[/b][/black][/url] [red]{[/red][url=http://perldoc.perl.org/functions/-X.html][black][b]-M[/b][/black][/url] [blue]$a[/blue] <=> [black][b]-M[/b][/black] [blue]$b[/blue][red]}[/red] [url=http://perldoc.perl.org/functions/glob.html][black][b]glob[/b][/black][/url][red]([/red][red]'[/red][purple]$logdir/*[/purple][red]'[/red][red])[/red][red])[/red][red][[/red][fuchsia]0[/fuchsia][red]][/red][red];[/red]

- Miller
 
Nice one Miller - that's perfect.
Thanks

Ceci n'est pas une signature
Columb Healy
 
Please note, the glob should actually be using double quotes instead of single quotes. Currently the $logdir variable won't be interpolated.

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top