Why does this have to be a "one-liner"?.
Why not code something simple? Is this some kind of "golf" test?
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { process_record ($1) if /^\s*START\s*(\w+)/; } sub process_record { my $start_value = shift; my @record; my $line; while (defined ($line=<DATA>) and $line !~ /^\s*END/) { push @record, $line; } my ($end_value) = $line =~ /^\s*END\s+(\w+)/; @record = map{"$start_value $end_value $_"}@record; print @record; print "\n"; } =prints abc xyz MAY abc xyz JUNE abc xyz JULY oue 2345 MAY oue 2345 JUNE oue 2345 JULY =cut __DATA__ START abc MAY JUNE JULY END xyz blah ....more blah... START oue MAY JUNE JULY END 2345
Update: I looked back upon this thread and these 2 lines could have been better written. I don't remember why I did what I did in the original coding. I do remember that I wrote the code in an attempt to get the OP "unstuck" and was surprised at the "one liner" requirement. Anyway the OP obviously doesn't care about this, but other future readers might...However, I will add that in this sort of situation, the difference probably doesn't matter at all...
# @record = map{"$start_value $end_value $_"}@record; # print @record; print "$start_value $end_value $_" for @record;

In reply to Re: Search between pattern and append by Marshall
in thread Search between pattern and append by Anonymous Monk

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.