abhishes has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perl monks,
I wrote the following code
Abhishek.
I wrote the following code
my $a = "The quick brown fox jumped over the lazy dog"; $a =~ tr/\n\n/\<br\/\>/; print "$a\n";
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.
regards,Abhishek.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What is the difference between s/ and tr/
by broquaint (Abbot) on Apr 15, 2003 at 15:01 UTC | |
Re: What is the difference between s/ and tr/
by Heidegger (Hermit) on Apr 15, 2003 at 15:03 UTC | |
Re: What is the difference between s/ and tr/
by valdez (Monsignor) on Apr 15, 2003 at 15:06 UTC | |
Re: What is the difference between s/ and tr/
by Mr. Muskrat (Canon) on Apr 15, 2003 at 16:24 UTC | |
Re: What is the difference between s/ and tr/
by mce (Curate) on Apr 15, 2003 at 15:05 UTC | |
Re: What is the difference between s/ and tr/
by dze27 (Pilgrim) on Apr 15, 2003 at 16:00 UTC |
Back to
Seekers of Perl Wisdom