#!/usr/bin/perl -w
#---------#---------#---------#---------#---------#---------#---------#---------
#
# title
#   find the youngest file in a list supplied from the command line
# author
#   idc@planetlarg.net 27 June 01
# description
#   HACKED VERSION OF dir-last-modified.pl
#   NOT WORKING
#   Get a list of files from the command line.
#   Find the most recently modified file.
#   Print a result (name and time in Unix seconds).
#   run like this
#      find /home/ateclarg/ | ./fl.pl
#
# modifications
#
#---------#---------#---------#---------#---------#---------#---------#---------
# setup
#
   use 5.005;
   use strict;
   use vars qw ($DEBUG);
   $DEBUG         = 0; # set to 1 (true) to print extra information to STDERR.


#---------#---------#---------#---------#---------#---------#---------#---------
# main
#   The main program goes here.
#   read from STDIN
    my $file;                  # current file passed in to examine
    my $mtime   = 0;           # current file modified time in unix seconds
    my $latest_mtime  = 0;     # most recent last modified time
    my $latest_file   = '';    # name of file with $latest_mtime

    while (<>) {
        $file = $_;
        chomp $file;
        next if $file =~ m/^\.\.?$/; # skip . (this) and .. (parent) entries
        next if -d "$file"; # skip directories
        my (
                  $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
                  $size, $atime, $mtime, $ctime, $blksize, $blocks
        ) = stat "$file";
        print "looking at $mtime $file\n" if $DEBUG;
        if ($latest_mtime < $mtime) {
         $latest_mtime  = $mtime;
         $latest_file   = $file;
        }
    }


# return the results
   print "\nthe winner: \n\t$latest_file $latest_mtime\n";


#---------#---------#---------#---------#---------#---------#---------#---------
# subs
#   all subroutines go below here.




#---------#---------#---------#---------#---------#---------#---------#---------


__END__

documentation

The "__END__" string is a token. It is the logical end of program text.
You can put anything you want after this token, such as an
instruction manual page; it will be ignored by the compiler.


