Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing <br> with carriage return

Status
Not open for further replies.

LotusE

Programmer
Nov 22, 2002
25
BE
A beginners question (again):

I want to replace all occurences of <BR> in a string with a carriage return. This is what I used:

$desc =~ s|<BR>|\r|g;

but it doesn't give me any result. The "<BR>" is still printed instead of actually performing a carriage return.

Thanks for the help.

Cheers

Steve
 
Code:
fish@spider:~$ perl -e '$a="one<br>two<br>three";$a=~s/<BR>/\r/gi;print "$a\n";
' | od -xc
0000000 6e6f 0d65 7774 0d6f 6874 6572 0a65
          o   n   e  \r   t   w   o  \r   t   h   r   e   e  \n
0000016
fish@spider:~$

There's nothing wrong with the code you posted. Do you need /i on your regex to make it case-insensitive? Do you really need "\n" instead of "\r"? How are you determining correct operation (note that if I had not used od in the test above, I would have just seen "three" as output)?

If you are happy about these points, your problem liew elsewhere in your code.

Yours,

fish

&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top