develooper Front page | perl.fwp | Postings from July 2003

Re: range operator for a condition in 2 steps

Thread Previous | Thread Next
From:
James E. Tilley
Date:
July 31, 2003 01:57
Subject:
Re: range operator for a condition in 2 steps
Message ID:
20030730213646.T4891@tilrman.com
Does

  if (/^BEGIN$/ .. (/^\s*$/ .. /^END$/) =~ /E/)

do what you want?

LP^>

On Thu, Jul 31, 2003 at 04:06:54AM +0200, Bart Lateur wrote:
> What I would want is to match lines in a loop, one line at a time, say,
> between a line cotnaining just "START" and a line containing just "END",
> but where the latter condition is only looked at, after an intermediate
> condition has been met first. In particular, I have to have seen a blank
> line first.
> 
> Looking at the skeleton program below, I would like as output to see
> these lines printed:
> 
>  1) from just underneath "2" till just above "4", blank line under "3"
>  2) from just underneath "6" till just above "14", blank line under "11"
> (The line just above "9" should be ignored)
>  3) from just underneath "17" till just above "20", blank line under
> "19"
> 
> and that using an expression that works pretty much like the ".." and/or
> "..." operators would. You see, I like the layout of the skeleton
> program.
> 
> I found a working (but quite ugly) solution, but I'll let you people
> chew on it first. You'll likely come up with something better, anyway. 
> 
> Bart.
> 
> Here's the skeleton program:
> 
> #!/usr/local/bin/perl
> while(<DATA>) {
>     if(/^START$/ .. /^END$/) {  # edit this condition
>         print;
>     }
> }
> __DATA__
> 1
> 2
> START
> 3
> 
> END
> 4
> 5
> 6
> START
> 7
> 8
> 9
> END
> 10
> 11
> 
> 12
> 13
> END
> 14
> 15
> 16
> 17
> START
> 18
> 19
> 
> END
> 20
> 21
> 22

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About