string char replacement

I have a variable $myStory that contains text and line breaks eg:

$myStory = "This is the first line\nthis is the second line\nthis is the thrid\n"

notice the line breaks.

I want print the string char by char, if the char is a "\n" I want to print a "<BR>"

I tried to convert all the \n to a <BR>'s with the following code but doesn't work with more that one charater:

$myStory =~ tr/\n/"<BR>"/;

can anybody help me out?
LVL 1
georgep23Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
$myStory =~ s/\n/<BR>\n/g;
# see
# perldoc perlre
0
 
ozoCommented:
$myStory =~ s/\n/<BR>/g;
0
 
developmentCommented:
have you tried
$line=~ s/\\n/<BR>/ig;
The g option on the end is global, so it does more than one in the line.  Ignore the $line, thats me being lazy.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
georgep23Author Commented:
ozo, cool, worked first time,

can never get my head around those search string things!


0
 
martinagCommented:
I'd do
$myStory =~ s/\n/\n<BR>/g;
which will make the source easier to read.

Points go to ozo though. As usual... :-)

Martin
0
 
georgep23Author Commented:
martinag,
I already did this ;)))


ozo can you repost as answer

thanks for your help everybody!
0
 
martinagCommented:
>> ;)))
Are those )s your double chins? ;-)

Martin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.