From the description of your algorithm, it sounds like
you want
$content to contain only a specific
string if that string is contained within the file in
question, right? Or do you really mean you want to replace
everything else with whitespace, so that
xxxJOHNxxx
would be three spaces,
JOHN, and then three spaces?
In the first case, how about
($file_text =~ /$string_to_match/) && $content = $string_to_match;
There's no need to do a substitution since you already know
what you want the value of
$content to be.
Moreover, you probably have a default value in mind if the
file fails to contain the match string, in which case you
could use the ternary operator to do it:
$content = ($file_text =~ /$string_to_match/) ?
$string_to_match : $default_failure_value;
Finally, if you
know the file contains the text,
and that's what you want in the
$content variable,
just do a simple assignment.
Update:
In case it's not obvious, I construed the question to
imply that the matching string was known beforehand,
rather than the delimiters. If the delimiters
are what is known beforehand, my advice is, well,
pointless.
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.