Need help perl - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help perl

tonyntonyn Posts: 7Member
Hi,

I want to compare a file "A" with all files in a directory call "DIR_b" and if file "A" has timestampe older than any file in "DIR_b" then report file "A" need to update.

Here is my code but it does not work
Thanks,
Tony

#!/user/bin/perl -w

$dir_A = "/home/tmp/test";
$dir_B = "/home/tmp/DIR_b"
@list = `cd $dir_B/; ls -t`;

$newest1 = '';
$newest1 = $list[0];
$newwest2 = "$dir_A/file_A";
print "Need to update $dir_A
"
if (-M "$dir_A" > -M "$newest1");

Comments

  • TrizenTrizen Posts: 5Member
    [code]my $dir_A = '/home/user';
    my $comp_file = '/home/user/data/file.ext';

    opendir DIR, $dir_A or die "Unable to open dir $dir_A: $!";
    while (defined($_ = readdir DIR)) {
    if (-f and (-M $comp_file > -M "$dir_A/$_")) {
    print "$comp_file is older than $dir_A/$_
    ";
    last;
    }
    }
    closedir DIR;[/code]
Sign In or Register to comment.