I liked this $/='end'; idea.

I've been working on another approach using the / /.../ / operator. I will admit that I have not mastered this technique, but it appears to be designed for processing multi-line records.

The code below produces the correct result, but my "gut feeling" is that it is overly complex. I hope some other Monk can show a better way with the "..." operator.

This operator is weird in that it sometimes returns values in exponential format, like 3E0 instead of just 3. I haven't figured out how to use this info in the most efficient way yet. Actually below, this info is not used, turn on the print statements to see what this does - it is interesting.

Anyway here is yet another approach for the OP to experiment with!

Update: my brain is working slowly today, but Perl DBI folks will be familiar with 0E0. This is the Perl way to return a "TRUE" value for numeric zero. I'm not sure how this xE0 stuff can be used here...

Update:I guess this is tangential to this discussion, but if you ever wondered "how can I return a "true" value meaning that the function worked and at the same time say that "zero" results were produced, returning the string '0E0' will do that trick.

#!/usr/bin/perl -w use strict; my $line=(); while (<DATA>) { next if /^\s*$/; # $flag is not necessary here, it is there to # show the return value of this triple dot operator # for /start/.../end/ if ( my $flag = ( /start /.../end/) ) { s/end.*/end/s; s/.*?start/start/; s/\n//; $line .= "$_"; # print "$flag\n"; #interesting 1, 2, 3E0 etc.... if ( $_=~ m/end$/ ) { print "OUT:$line\n"; $line =(); } } } #Prints: #OUT:start 1asdasd asdasdasd asdasdas end #OUT:start 2as asdas dasdasdad asdasddas end #OUT:start 3asdsadsdasddasds sdasdas asdasdasdasd asdasdsa asdasd asda +sdasd and this is an evenlonger way to stop a line with )&)9867 some +end #OUT:start 4another line end __DATA__ asdasd start 1asdasd asdasdasd asdasdas end asdasdas adasdas start 2as asdas dasdasdad asdasddas end qweqwe asdasd start 3asdsadsdasddasds sdasdas asdasdasdasd asdasdsa asdasd asdasdasd and this is an even longer way to stop a line with )&)9867 some end garbage start 4another line end abc

In reply to Re^2: how to get context between two flag by Marshall
in thread how to get context between two flag by cxfcxf

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.