0

I am trying to read the file from some other directory, it for me every things looks good but unfortunately neither i am getting any error nor any output.

I am working on windows Pc.

Here is My code:

use strict;
use warnings;

use Cwd;

#chdir('C:\\APTscripts\\APStress\\Logs');
chdir('C:\\Mahi_doc\\Apstress_logs');
my ($dir_01,$dir_02);
my @FILES;
$dir_01 = getcwd;

#print "$dir\n";
opendir(DIR_01, $dir_01) ;
@FILES=readdir(DIR_01);
close(DIR_01);
my $count=12;
my $lines;
for my $dir_02 (@FILES)
{
  #print"$dir_02\n";

 if ( -d $dir_02)
 {
opendir (DIR_02, "$dir_01"."/"."$dir_02") ;
 while(our $file = readdir(DIR_02))
  {
    if($file =~ /APStress.*UIlog/g)
     {
     #  print"$file\n";
       open(FH,$file) or die "can not open the file $!\n"; 
        while (defined(my $lines = <FH>))
        { 
        print"$lines\n";
        if($lines=~ m/WATCHDOG/ || $lines=~ m/Excessive JNI/gi )
        {#chks for watchdog/excessive jni issue exist
          print "Got it\n";
        }
        elsif($lines=~ m/installd: eof/gi)
        {
            print "EOF:Got it  \n";
        }
       }
     }
   }
  } 

}
5
  • I have no idea that how to attach the file otherwise i would have attached the log file also which i am trying to read. Commented May 27, 2013 at 11:07
  • You are not doing any error checking. So why do you think your script would show any errors? Commented May 27, 2013 at 11:08
  • die "can not open the file $!\n"; is not giving me any error that means i can say that file is getting open , please correct me if i am wrong. now what else error checking i should perform ? Commented May 27, 2013 at 11:15
  • May be you haven't any directories under $dir_01. Commented May 27, 2013 at 11:20
  • @42 print"$file\n , files are getting print here .. so i dont think that will be a issue Commented May 27, 2013 at 11:29

1 Answer 1

2

In the open clause, give the full path for the file:

open(FH, "$dir_01/$dir_02/$file") or die "can not open the file $!\n"; 

and better use 3 arg open and lexical file handler:

open(my $FH, '<', "$dir_01/$dir_02/$file") or die "can not open the file $!\n"; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.