in reply to Range Operator Mysteries

This is not intended as a flame, so no offence, please. Nevertheless, I would like remark the resemblence to a thread from a week ago: Control Flow Puzzle. Dominus' problem demanded a more sophisticated delimiter, but the essence was not very different. Does this mean we need an extra Q/A entry?

How about Yet Another Solution? I proposed a pop kind'o'solution, then:

undef $/; $_=<>; s/(\n\037.*?\n\* Menu.*?\n\037)//; $mymenu=$1;
With a little molding:
undef $/; $_=<>; while ( s/={10,}(\n.*?\n)(={10,}\n)/$2/s ) { push(@myblocks,$1); } print "I counted ".scalar(@myblocks)." blocks\n"; while ( $myblock=shift(@myblocks) ) { open( OUT, ">$myname" . $i++); print OUT $myblock; close OUT; }
The use of {10,} makes the code insensitive for the number of ='s. If you would use =+, you would also match ='s that were used in the text blocks. I leave the $2 in place, to facilitate the next match. The question mark ungreedies the wildmark. I haven't run the code, but it seems quite straightforward (aka likely without flaws).

Have fun,

Jeroen
I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)

Update: chipmunk pointed to some mistakes. Have been fixed.

Replies are listed 'Best First'.
Re: Re: Range Operator Mysteries
by chipmunk (Parson) on Dec 01, 2000 at 20:25 UTC
    A slight flaw: without the /s modifier on the substitution, this code will only match blocks that are one line long. (There's also a typo with the quoting of the string 'I counted'.)

    I like the use of {10,} to make sure the delimiter is at least a certain length.