2

Need some more help on flip-flop operator Below is my sample data:

LS             SPID     ASP            SPID
3-59           MGW05    
SLC ACL PARMG ST                   SDL                             SLI
 0  A1  17    C7STH-1&&-31         MSC19-0/RTLTB2-385
LS             SPID     ASP            SPID
3-618          ETRC18   
SLC ACL PARMG ST                   SDL                             SLI
 0  A2   0    C7ST2C-4             ETRC18-0/RTLTB2-417
 1  A2   0    C7ST2C-5             ETRC18-0/RTLTB2-449
END

The data of interest for me starts from string 'LS SPID ASP SPID' and ends at either next 'LS SPID ASP SPID' or END (if there's no next LS line). Is it possible to get this using flip-flop operator? I read this data into an array (@linesread) and then tried to loop over the array using the below code and it is not working. Is the problem because i cannot loop over the same line twice? Any other solution?

P.S: I am using the ... operator as needed.

foreach (@linesread) {
    if (/^LS\s*SPID\s*ASP\s*SPID$/ ... (/^LS\s*SPID\s*ASP\s*SPID$/ || /^END$/)) {
    print "$. \t $_\n";
    }
}   
pkr13
  • 107
  • 2
  • 10

1 Answers1

3

The range operator itself cannot be configured to evaluate the left side immediately. But you can try

if (my $r = /^LS\s*SPID\s*ASP\s*SPID$/ ... (/^LS\s*SPID\s*ASP\s*SPID$/ || /^END$/)) {
    print "$. \t $_\n";
    redo if $r =~ /E0$/;
}
choroba
  • 231,213
  • 25
  • 204
  • 289
  • Thanks a lot for quick reply. I read about this special sequence E0 being appended to value returned, but couldn't visualize about using this to solve my problem. Thanks! – pkr13 Jan 04 '12 at 13:55