Need assistance in the perl script . Below script gives me the results of all the files and directories with mtime with no issues . But i wanted to have a file and specify all the directory locations and use that file as reference and get results . Any ideas are highly Appreciated .
#!/usr/bin/perl -w
use warnings;
use strict;
use Time::Local;
use File::Copy;
my @dirs = ("<path1>","<path2>","<path3>");
my %seen;
while (my $pwd = shift @dirs) {
opendir(DIR,"$pwd") or die "Cannot open $pwd\n";
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
if (-d $file and ($file !~ /^\.\.$ARGV[0]$/) and !$seen{$file}) {
$seen{$file} = 1;
push @dirs, "$pwd/$file";
}
next if ($file !~ /\.$ARGV[0]$/i);
my $mtime = (stat("$pwd/$file"))[9];
print "$pwd \t $file \t", scalar(localtime($mtime));
print "\n";
}
}
here what i tried as an example and implemented the same on the main script . But it works with only one path not multiple paths
#!/usr/bin/perl
use strict;
use warnings;
open (my $fh, '<', 'test.txt') || die "Could not open test.txt: $!\n";
my @test = grep { $_ !~ /^#/ } <$fh>;
print @test;