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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.