in reply to Problem in using range operator

I think the problem is that when the ".." evaluates the left hand side and it becomes true, it will remain true until the right hand side becomes true. So once you are in range for, say line "A" becuase of STMT1=BEGIN, it will still be in range when you test /STMT2=BEGIN/../STMT2=END/ since it hasn't seen /STMT2=END/ yet. The following works ok, but not sure it's exactly what you want (BTW, "use strict" might help.)
while ( defined ($_ = <DATA>) ) { if (/RULE=$rule/../^END$/) { chomp $_; if ($_ =~ /^NUMOFRULES/) { # Get the number of rules @rulenos = split(/=/); } my $e = $rulenos[1]; if (/^STMT1=BEGIN$/../^STMT$e=END$/) { if ( !($_ =~/^STMT/)) { print $_; } } # for ($i = 1; $i <= $rulenos[1]; $i++) { # if (/^STMT$i=BEGIN$/../^STMT$i=END$/) { # if ( !($_ =~/^STMT/)) { # print $_; # } # } # } } } __DATA__ RULE=test BEGIN NUMOFRULES=2 STMT1=BEGIN A B C STMT1=END STMT2=BEGIN X Y Z STMT2=END
Update. a subtle point which I didn't know until thinking about this problem is that: each .. keeps its own state of in range or not in range, here "each" is NOT dependent on what the left-right operators are, so each iteration of a loop only counts as one range operator, and one state, as shown by the following code:
use strict; my @data = <DATA>; foreach(@data){ chomp; if(/START1/../END1/){ print "1: $_\n"; } if(/START2/../END2/){ print "2:$_\n"; } } print "\n\n"; foreach (@data){ foreach my $i(1..2){ if(/START$i/../END$i/){ print "$i:$_\n"; } } } __DATA__ START1 A B C END1 START2 X Y Z END2
output is as follows, notice the difference:
__OUTPUT__ 1: START1 1: A 1: B 1: C 1: END1 2:START2 2:X 2:Y 2:Z 2:END2 1:START1 2:START1 1:A 2:A 1:B 2:B 1:C 2:C 1:END1 2:START2 1:X 2:X 1:Y 2:Y 1:Z 2:Z 1:END2 2:END2