At worst, another way with the ternary (or "conditional") operator:
use vars qw ( $message);
$message = qq ( Foo bar <font size="7"> phrase here </font> blivits. )
+;
$message =~ s#(\d+)#($1 > 5) ? 5 : $1#eisg;
if ( $1 ) {
print "\n After s###, \$1 is: $1 \n ...and revised \$msg is:
+$message \n";
}
else
{
print "\n no \$1 found \n";
}
and output is:
After s###, $1 is: 7
...and revised $message is: Foo bar <font size="5"> phrase here </font> blivits.
- the $message html fragment is well-formatted... for 4.0, but display elements are now better (well, that's what the experts say) done with css
- the "sig" regex modifiers are not needed with this $message but might well be with more typical .html
- and, while matching on <font size=" before the 7> is omitted only to keep the example simple (and is easy enough to add), this is a very limited and profoundly un-extensible method -- better to use an html parser, as suggested elsewhere. For example, a web'ster using <font... may well have multiple and/or variant forms of elements in a single font tag, as, for example,
<font color="red" size=+1...>
- and, finally, despite generous efforts by OP, I can't see how Re^2 or Re^3 can or do work ... even with "<"s replacing "["s
...so would welcome education.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|