Hi
arturo,
The solution you presented will overwrite the output-file on each occurance of the section start. Furthermore, writing to closed filehandles isn't a very clean solution, IMHO.
You could try to use the magic '..' operator:
open OUT, '>&STDOUT' or die;
while ( <DATA> )
{
print OUT if /start-marker/../end-marker/
and !/(start-marker|end-marker)/;
}
close OUT or die;
__DATA__
a
b
c
start-marker
d
e
end-marker
f
g
start-marker
h
i
end-marker
j
k
This will print the lines within the markers (thus: d,e,h and i in my example) but ignores the markers.
HTH,
(update: fixed some layout issues and used the actual '..' operator instead of the '...' one!).
-- JaWi
"A chicken is an egg's way of producing more eggs."
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.