Once again, I just want what is in between first occurrence of "Services" and "Users".
I'm assuming that you aren't interested in the lines with the "======" stuff. Based on that, here's how I would approach the problem.
use strict; my $file; open(DATA,"<data.txt") || die "Unable to open file 'data.txt': $!\n"; { local $/; $file = <DATA>; } close(DATA); my ($selection) = ($file =~ m/^.+?Services.+?[=]+(.+?)[=]+/is); my (@lines) = split /\n/,$selection; for (my $i=0;$i<=$#lines;$i++) { $lines[$i] =~ s/\n//; print "Line $i: $lines[$i]\n"; }
Which produces the following output:
Line 0: Line 1: blah Line 2: glah Line 3: sfsd Line 4: Line 5: Line 6: asfsdf Line 7: afsafdf
Although BrowserUK's code is probably better, the code above may be easier to follow for some folks (such as myself). Also, I should note that I do lose a blank line at the end of the captured section when I use the split command. Again, I'm assuming that won't create problems for what you're trying to do.
Anyways, this gives you an example of another approach to solving the problem.
In reply to Re: Matching ranges
by dasgar
in thread Matching ranges
by ldbpm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |