> What's a quick way to get the name of the newest file in a directory? 

ls -ltr 

and it'd be the last file listed (-ltr Long listing, by Time, in Reverse 
order).  I don't know of a way to make opendir/readdir use a different 
order (by name, case sensitive as your OS) but a trick to get the last 
file name (note, the missing lowercase L - this'll get the last entry in 
the dir, file or dir):
ls -tr | tail -1

can be used w/ backtics to get the name in dir.  Or something like:
my @files = `cd $some_dir ls -ltr`;
my $last_file = '';
foreach my $file_or_dir ( @files ) {
    next if $file_or_dir =~ /^d/;
    $last_file = $file_or_dir;
}    # foreach $file_or_dir

print "Last file is: $last_file\n";

a

Andy Bach
Internet: [EMAIL PROTECTED]
VOICE: (608) 261-5738  FAX 264-5932

Have you noticed that people whose parents did not have 
children, also tend not to have children?
  - Robert J. Kolker in sci.math, "Re: Genetics and Math-Ability"
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to