Perl

Moderators: Jonathan
Number of threads: 1257
Number of posts: 3636

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help perl Posted by tonyn on 24 Feb 2011 at 6:53 PM
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 \n"
if (-M "$dir_A" > -M "$newest1");

Report
Re: Need help perl Posted by Trizen on 4 Nov 2011 at 3:53 AM
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/$_\n";
            last;
        }
}
closedir DIR;




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.