dimanche 25 octobre 2020

Perl: if else condition getting stuck on elsif

I am reading a file which has data like this

a  be  cd  d
e  fe  g   h 
ae be  cd  d
q  wj  e   r

My code:


use warnings;
use strict;

open(tempp1,"<$temp1") or die "Could not open file $temp1: $!";
 
while(my $line=<tempp1>) {
  my @rw = split " ",$line;

   if ($rw[0] eq "e" and $rw[1] =~ /^f*/ ) 
    {print ...}

   elsif ($rw[0] eq "a" and $rw[1] =~ /^b*/ and $rw[2] =~ /^c*/ ) 
    {print ...}

   elsif ($rw[0] eq "ae" and $rw[1] =~ /^b*/ and $rw[2] =~ /^c*/ ) 
    {print ...}
}
close tempp1;

Now if I run then it only prints for only 1st and 3rd conditions ($rw[0] eq "e" and $rw[1] eq "f" ) and ($rw[0] eq "ae" and $rw[1] =~ /^b*/ and $rw[2] =~ /^c*/ ) skipping the 2nd one but when I remove the 3rd condition the it is checking the 2nd condition and printing for it. What's the problem?

Aucun commentaire:

Enregistrer un commentaire