Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Finding oldest file in directory

by Roy Johnson (Monsignor)
on Oct 18, 2004 at 19:12 UTC ( #400283=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $oldest;
    my $oldtime = 0;
    ...
        ($oldest, $oldtime) = ($_, $thistime);
      } 
    }
    
  2. or download this
    use List::Util 'reduce';
    my $file = (reduce {$a->[0] < $b->[0] ? $a : $b}
                       map {[(stat)[10],$_]}
                       glob '*.pl'
               )->[1];
    
  3. or download this
    my $file = reduce {(stat $a)[10] < (stat $b)[10] ? $a : $b}
                      glob '*.pl';