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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help perl

tonyntonyn Posts: 7Member

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

#!/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");


  • 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/$_
    closedir DIR;[/code]
Sign In or Register to comment.