Re: range operator for a condition in 2 steps

Bart Lateur <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Organization MediaMind
Message-ID <[email protected]>
On Wed, 30 Jul 2003 21:36:46 -0500, James E. Tilley wrote:

>Does
>
>  if (/^BEGIN$/ .. (/^\s*$/ .. /^END$/) =~ /E/)
>
>do what you want?

s/BEGIN/START/ to plug it in the skeleton.

And yes, that's perfect. Quite elegant too. Very much so.


Here's my own solution:

	my $pre;
	while(<DATA>) {
	    if(my $count = (($pre = /^START$/) .. 
	    	(/^$/ && undef $pre, !$pre && /^END$/))) {
	        print "$count: $_";
	    }
	}

What I don't particularly like about it, is how it needs an extra outer
scope variable, $pre, to hold a flag to store the intermediate
condition.

BTW with the additional variable $count capturing the result of the
expression,  it's easier to keep track of what happens.

-- 
	Bart.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.