mercredi 4 janvier 2017

pattern not printing while trying to match same string on two files

I am trying to find pattern from two different files and then need to sum the last values of two filesand then print sum with first ,second and third field(sum) in xls...this is so far i wrote but it is printing value of first if loop not sure why not printing for second.if somone having better logic than below to do same operation ...

file1.txt 
L01B,"ABC",832048921.62
L01E,"DDD",70675364.68
L02A,"ZZZ",19747732853.37

file2.txt
L01B,"AAA",832048921.62
L01E,"DDD",70675364.68
L02A,"ZZZ",19747732853.37
#!/usr/bin/perl

use warnings;
use strict ;
  use Date::Simple qw(d8);

  my $firstdate = $ARGV[0];
  my $d1 = d8($firstdate);
 my $seconddate = $ARGV[1];
  my $d2 = d8($seconddate);
  my $f1=$d1-> format ('%d_%m_%Y');
  my $f2=$d2-> format ('%d_%m_%Y');
  print  " $f1 \t";
  print "$f2\n";
  open(my $fh1, '<', $f1) or die "Could not open file '$f1' $!";
  open(my $fh2, '<', $f2) or die "Could not open file '$f2' $!";

  while ( my $line1 = <$fh1>) {
           chomp $line1;
           if ($line1 =~/L01B/){
               my @array = split /[,]+/,$line1;
               {
               while (my $line2 = <$fh2>)
               {
               if ($line2 =~/L01B/){

               my @array1  = split /[,]+/,$line2;
               print " match found sec $array1[0]\n";
              print " match found sec $array1[1]\n";
              print " match found sec $array1[2]\n";
              print " match found first $array[0]\n";
              print " match found first $array[1]\n";
              print " match found first $array[2]\n";
              }

              }
              }
             }
             if ($line1 =~/L01B/){
               my @array2 = split /[,]+/,$line1;
               {
               while (my $line2 = <$fh2>)
               {
               if ($line2 =~/L01A/){

               my @array3  = split /[,]+/,$line2;
               print " match found sec $array2[0]\n";
              print " match found sec $array2[1]\n";
              print " match found sec $array2[2]\n";
              print " match found first $array3[0]\n";
              print " match found first $array3[1]\n";
              print " match found first $array3[2]\n";
              }

              }
              }

             }

             }
    close($fh1);
    close($fh2);        

Aucun commentaire:

Enregistrer un commentaire