I've been trying several ways in manipulate a string to replace everything in between two sets of strings and so far no luck. I've even used the /s and /m modifiers since the Deitel book was talking about multiline and single line figuring that the "." character would match everything but newline, which I will/do have.
I'm not sure if the $last string matches right after the the $first string, but let's just say that it does and there's only one in the entire $string for now, but additional ways to do this would be a bonus for future use.
Thank you in advance for all your help.
my $string='foo bar foo bar
<span id="box1" class="box1">
foo bar
foo bar
</span> foo bar';
$first='<span id="box1';
$last='/span>';
$reserve='<!-- BOX1 -->';
$string =~ s/$first(.*?)$last/$reserve/;
So just to be clear, how can I get the substitution operator to replace everything in my
tag with a another tag such as a comment?
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.