On Jun 1, Steve said:
>use File::stat;
>use time::local;
Heh, that's windows for you.
use time::local;
works on windows, but you meant to write
use Time::Local;
You see, on windows, 'time/local.pm' and 'Time/Local.pm' are the same
thing, because the OS is case-insensitive. However, when you do 'use',
Perl does TWO things:
BEGIN {
require time::local; # this loads Time/Local.pm ok
time::local->import; # too bad there is no time::local package
}
You see, Time/Local.pm defines a namespace called Time::Local, *not*
time::local. Perl is NOT case-insensitive!
Oh, but you don't even use Time::Local here, so you don't need the module
anyway.
>$filename='C:\dosperl\bin\junk2.txt';
>$filename2='F:\Palm\Add-on\diary05202117.17.pdb';
>$sb=stat($filename);
>$sb2=stat($filename2);
>$sb3=localtime;
I think you meant to use time(), and not localtime(). localtime() in
scalar context returns a date string, but time() returns the number of
seconds.
>if ($sb->mtime < $sb3)
>{
> printf "The file you are checking is %s\n",$filename;
> print "This file was created today in the if\n";
> printf "The file is older than today\n";
>}
>elsif ($sb->mtime > $sb3)
>{
> printf "The file you are checking is %s\n",$filename;
> print "This file was created today in the else\n";
> printf "The file was created today\n";
> printf "%s\n%s\n",$sb->mtime,$sb3;
>}
You're using printf() rather uselessly if you're just putting in
variables.
Also, Mark-Jason Dominus (MJD) gave a talk at my workplace Wednesday
evening about "red flags" -- one of which was repetition of code.
Instead of writing all this out, once for EACH file, make an array of
files to check:
my @files = qw(
c:\check\this\file
d:\this\file\too
);
Then, print the information for each file in that array:
my $now = time;
for my $f (@files) {
my $mod = stat($f)->mtime;
my $is_old = $mod > $now; # it'll be rare if this is false...
print "The file you are looking at is $f\n";
printf "This file is %s than today\n", $is_old ? "older" : "younger";
printf "It was modified on %s\n\n", scalar localtime($mod);
}
That's a generic output format.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **