A recent post to SOPW (which I cannot locate just now) asked how to shorten something like this:
$str = "the boy walked the dog";
$str =~ s/walked/fed/;
$str =~ s/boy/girl/;
$str =~ s/dog/Audrey II/;
by removing all the $str =~ stuff. There were multiple solutions, but I think the question was really along the lines of why we can't access the matched string easily. That is, whey can't we chain the substitutions? Wouldn't chaining the substutions be nice? Is there a string class that allows this kind of thing? It just seems more perlish to be able to chain the substitutions.
--traveler
-
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.
|