in reply to Re^2: grab oldest file
in thread grab newest file

If you really want to use the least resources: Updated for newest file:
my $report = do { opendir my $dh, $path or die "open '$path' $!"; my ( $name, $mtime ) = ( '', ~0 ); while ( my $file = readdir $dh ) { stat "$path/$file"; ( $name, $mtime ) = ( $file, -M _ ) if $file =~ /B1006/ and $m +time > -M _; } $name; };

Replies are listed 'Best First'.
Re^4: grab newest file
by shmem (Chancellor) on Jul 07, 2006 at 06:36 UTC
    Comparing mtime (timestamp) and -M is bogus. -M gives you the script start time minus file modification time, in days.

    update - oops, sometimes I'm a lousy reader - the referred post compares only -M against -M. Read the above just as a general statement ;-)

    thanks jwkrahn

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      The code I posted is only comparing the -M value with other -M values. The $mtime in the code is just a variable name.