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

Re: range operator for a condition in 2 steps

Thread Previous | Thread Next
Bart Lateur
July 31, 2003 04:08
Re: range operator for a condition in 2 steps
Message ID:
On Wed, 30 Jul 2003 21:36:46 -0500, James E. Tilley wrote:

>  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

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


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About