Instead of depending on the file name to tell you how old it is, maybe you could use the age of the file as given by the "-M" function (read about it via perlfunc -f -X.
Since the value returned by -M is in days, you have to know that 1 minute equals 0.0006944 days:
#!/usr/bin/perl
use strict;
my $Usage = "Usage: $0 pathname\n";
die $Usage unless ( @ARGV == 1 and -d $ARGV[0] );
my $dir = shift;
opendir( DIR, $dir ) or die "opendir $dir failed: $!\n";
my @newfiles = grep { -f "$dir/$_" && -M _ < 0.000694445 } readdir DIR
+;
printf( "Found %d new files at %s\n", scalar @newfiles, scalar localti
+me );
print " " , join( "\n ", @newfiles ) . "\n" if ( @newfiles );
(updated to be a little more accurate about the age limit -- .0007 was probably too loose.)
Now, if there happens to a file that was created an hour (day, week, month, year) ago and was modified within the last minute (i.e. its content changed, by appending or altering data), it will be reported as "new" regardless of its name, along with any file that was actually created within the last minute. If you don't want that, then you'll need to fall back to checking the file names.
(I tried the "-C" function as well, but on my macosx/BSD system, it behaved the same as "-M" -- still, you might test it under solaris to see if "inode change time" is different in some useful way from "modification time".)
Note that -M reports file age relative to the time at which your script began running, so the length of time it takes to run the script has no effect on the results (the last file fetched from the directory will be judged by the same criterion as the first file, no matter how many files are in the directory). |