vendredi 27 mai 2016

Perl Loop not filtering right results

So guys I am searching through a mutliple log files using perl script and this is my while loop. for some reason I think my loop is searching only once and returning the first values it found. This result output is not returning all the possible values after reading the files.There are some missing values.

   #str_1,2,3,4 are my strings I am searching for 

    while ($line = <$fh>){

       if($line !~ /$str_1/ && $line =~ /$str_2/){
       open($fh, '>>report.txt');
       print $fh "$file : $line";
       close $fh;
        }
    if($line !~ /$str_3/ && $line =~ /$str_4/){

     open($fh, '>>report.txt');
     print $fh "$file : $line";  
       close $fh;

        }

    }

   }

      output: Number of Attendance = 1 INFO:21
              Number of Attendance = 2 INFO:21
              Number of Attendance = 1 INFO:21 

   # There are results such as Number of Attendance = 8 INFO:21 which my code is not able to search.

Aucun commentaire:

Enregistrer un commentaire