trowa has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks! Anyone offering perls of wisdom? Basically, I have populated this hash with ip addresses for key values and corresponding file names for list values. The purpose, is to upload various files to different ftp servers based on ip ranges. This script is currently in production, but there are some doubts to whether we are getting duplicate files around midnight. The script kicks off by cron every 5 min., and files are coming into to this server (via tftp) all the time. My question is, does the file test operator -M (see 2 lines ### LOOK HERE ### AND HERE) evaluate properly if the script kicks off prior to midnight, let's just say 23:56:00, but it is 00:01:59 when the script gets around to check the last modified date of the file, which turns out to be last modified (the file) at 23:59:59? Basically, the question is, does -M work if spanned across midnight? Does -M evaluate based on the date value in addition to the time value (min,seconds)? I guessing, it evaluates in terms of seconds (or even milliseconds?) based on the UNIX time since 19xx or something like that. Please, someone make me look like the fool that I am!
#use Shell; use Symbol; use IO::Handle; #use Data::Dumper; use Net::FTP; #use File::Copy; my @bsips = qw( 192.168.1.132 192.168.1.133 192.168.1.134 192.168.1.135 ); my @ipsegs = qw( 10.10.10 10.20.20 10.30.30 10.40.40 ); my $uid = "user"; my $pwd = "password"; my $rdir = "/rdir/data"; my $ldir = "/ldir/data"; my $tmpdir = "/opt/perl/tmp"; my $pathlog = "/opt/perl/tmp/ftp.log"; ## more subs here, not included (hash population) sub ftp2bs { ($uid, $pwd, $rdir, $ldir, $pathlog, $bsips, $hbs) = @_; for $gx (keys %$hbs) { #print "$gx ------------- $gx\n"; chdir "$ldir" or die "error: $!\n"; $ftp=Net::FTP->new($gx); neterr($ftp); $ftp->login($uid,$pwd); neterr($ftp); $ftp->binary(); neterr($ftp); $ftp->cwd($rdir); neterr($ftp); for $i (0..$#{$hbs{$gx}}) { my $fnx = $hbs{$gx}[$i]; ### LOOK HERE if (-w $ldir."/".$fnx && -M $ldir."/".$fnx>0.0007) { #print "$gx: $hbs{$gx}[$i]\n"; $ftp->put($ldir."/".$fnx); # print $ftp->message(), ""; # neterr($ftp); } } $ftp->close; neterr($ftp); $ftp->quit; neterr($ftp); } } sub io4ls { ($tmpdir, $pathlog, $hbs) = @_; for $gx (keys %$hbs) { my $fhw = gensym; open $fhw, ">>$tmpdir/$gx.list" or die "error: $!\n"; #print "$gx ------------------- $gx\n"; for $i (0..$#{$hbs{$gx}}) { my $fnx = $hbs{$gx}[$i]; ## AND HERE if (-w $ldir."/".$fnx && -M $ldir."/".$fnx > 0.0007) { #print "$gx: $hbs{$gx}[$i]\n"; print $fhw "$hbs{$gx}[$i]\n"; } } close $fhw; } } ftp2bs($uid, $pwd, $rdir, $ldir, $pathlog, \@bsips, \%hbs); io4ls($tmpdir, $pathlog, \%hbs);

Replies are listed 'Best First'.
•Re: file test modifier -M and midnight rollover
by merlyn (Sage) on Mar 20, 2002 at 20:31 UTC
    -M always works relative to $^T. If you want to force a particular relative value, you can set $^T!
    $^T -= $^T % 86400; # roll back to prior GMT midnight
    Or, just use stat and get the absolute values without regard to the current time, and generate your own range info.

    -- Randal L. Schwartz, Perl hacker

      Okay, thanks for the info. -M tied to $^T, interesting. And, BTW, thanks for the Schwartzian transform also...