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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.