Hello Perl monks,
I wrote the following code
my $a = "The quick
$a =~ tr/\n\n/\<br\/\>/;
It produced the wrong results "The quick<<brown fox<<jumped<<over the<<lazy<<dog"
I removed the tr/ statement and inserted the following code
$a =~ s/\n\n/\<br\/\>/g;
and the program gave me the right results "The quick<br/>brown fox<br/>jumped<br/>over the<br/>lazy<br/>dog"
But I can't understand why did the tr/ didn't work and why s/ did? what is the differnce between them. I used to think that they are two ways of doing the same thing.
thanks for your help.
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>
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
Want more info? How to link or
or How to display code and escape characters
are good places to start.