Paul Harwood wrote: > > I am trying to compare a file's modified timestamp with the current date. > > I can use 'stat' to get the timestamp of the file but am not sure how to > compare it to the localtime(). More importantly I want to be able to > quantify the difference in days, month, hours and minutes. > > Any suggestions?
#!/usr/bin/perl use warnings; use strict; my $now = time; my @files = grep -f, <*>; # all non-hidden files for my $file ( @files ) { my $mtime = ( lstat $file )[ 9 ]; my @diff = reverse +( gmtime $now - $mtime )[ 0 .. 5 ]; # adjust year and day $diff[ 0 ] -= 70; $diff[ 2 ]--; printf "File: %s is %d year%s, %d month%s, %d day%s, %d hour%s, %d minute%s and %d second%s old\n", $file, map { $_ == 1 ? ( $_, '' ) : ( $_, 's' ) } @diff; } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]