Searching the file of below pattern through perl script from different location

Hi All,

I am creating a small per script but I am getting the error "Unable to open file because No such file or directory".My code is below.I am trying to go into the below location so using chdir and then seraching the log files of below pattern.

#!/usr/bin/perl -w
 chdir '/projects/stp/stpbuild/logs/BuildLogs/';
 $a = `ls -ltr | grep STP-201211`;
 open (TEMP, "$a") || die "Unable to open file $a because $!\n";
 @files = (<$TEMP>);
 foreach $file (@files) {
   print $file . "\n";
 }

Hi anuragpgtgerman,

What is the result of

print "(($a))\n";

just before the open instruction?

And if I got you right, instead of using external commands ( ls and grep ), you could write a terse version using directory handles and the grep built-in operator:

#!/usr/bin/perl -w
opendir my $dh, '/projects/stp/stpbuild/logs/BuildLogs/' or die "Could not opendir: $!\n";
for my $file (grep /STP-201211/, readdir $dh) {
 print "File : $file\n";
}

its working now