in reply to Matching ranges

I am attempting to match between the first match of "Services", and not after, but I am getting everything using the following code:
I cannot reproduce that. I do not get the lines between 'Users' and the next 'Services' (as expected).
Once again, I just want what is in between first occurrence of "Services" and "Users".
use 5.010; while(<>) { state $done; if ( /^Services$/ .. /^Users$/ ) { print "$_"; $done = 1; next; } last if $done; }
Or:
while(<>) { if (my $r = /^Services$/ .. /^Users$/ ) { print $_; last if $r =~ /E0$/; } }

Replies are listed 'Best First'.
Re^2: Matching ranges
by ldbpm (Initiate) on Sep 02, 2010 at 12:42 UTC

    This is the weirdest parsing problem I have ever encountered

    while(<>) { if (my $r = /^Services/ .. /^Users/ ) { next if $_ =~ /^Services/; print $_; last if $r =~ /E0$/; } }

    produces output without the "Services" line, but the following does not (at least for me):

    while(<>) { if (my $r = /^Services/ .. /^Users/ ) { next if $r =~ /^Services/; print $_; last if $r =~ /E0$/; } }

    even when I try to exit early, $r is not seemingly not respected

    while(<>) { if (my $r = /^Services/ .. /^Users/ ) { #next if $_ =~ /^Services/; exit if $r =~ /^Services/; print $_; last if $r =~ /E0$/; } }
      A slight bit more "regex kung-fu" is needed.

      #!/usr/bin/perl -w use strict; my $num =1; while(<DATA>) { if ( (/^Services\s*$/../^Users\s*$/) =~ /^(\d+)(?<!^1)$/ ) { last if $1 <= $num++; #only first Services section next if /^====/ || /^\s*$/; #if you don't want these print "$_"; } } =prints blah glah sfsd asfsdf afsafdf =cut
      Data Used: I highly recommend reading: not only Flipin good, or a total flop?, but some of the responses in that node that talk about eliminating start and end conditions - shows how to do "regex-fu" like above!

        Sir, you are a true PerlMonk, with special kung-fu-regex skills. Thank you much!

      Your $r =~ /^Services/ is the problem. Try running this and look at printout of values of $r.
      while(<>) { if (my $r = /^Services/ .. /^Users/ ) { #next if $r =~ /^Services/; next if /^Services/; print "$r:$_"; last if $r =~ /E0$/; } }

        Most excellent ... Seriously thanks ...

Re^2: Matching ranges
by ldbpm (Initiate) on Sep 02, 2010 at 12:02 UTC

    Your second piece of code work well. Thanks, because I like to use ranges in this particular case.