in reply to Duplicating the 'cp' command's '-u' switch

You can use the built-in stat function to determine the modification time of a file.
use strict; use warnings; my $from = "first.txt"; my $to = "new.txt"; copy_if_newer($from, $to); sub copy_if_newer { my ($from, $to) = @_; # test for file modification time return 0 if (stat $from)[9] <= (stat $to)[9]; # do the actual file copy here with File::Copy, etc. # return 1 to indicate success return 1; }

Replies are listed 'Best First'.
Re: Re: Duplicating the 'cp' command's '-u' switch
by nysus (Parson) on Dec 10, 2003 at 03:17 UTC
    Forgot about that function. Easy enough. Maybe I'm being too lazy. :)

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks