nl2br in Perl? - Need to format output and add newlines

Experts,

I am outputting a longtext field from my db to html.  I need to show line breaks as the output is one continuous string.

I know in PHP you can use nl2br which adds <br> however I cant find a function in Perl to do this.

Please help.
mhouldridgeAsked:
Who is Participating?
 
nitinsawhneyConnect With a Mentor Commented:
sorry missed a slash...

$longTextFile =~ s/\n/<br>/g;
0
 
nitinsawhneyCommented:
In perl you do it with power of regex string replacement

$longTextFile =~ s/n/<br>/g;

Here longTextFile is the scalar containing your output.

Cheers
0
 
SmartIntelCommented:
Store each line in a variable and add <br> at the end using regular expression

$ine=~s/(.)+/$1<br>/g;
 
now print each line in a HTML file
0
 
mhouldridgeAuthor Commented:
Hi,

Thanks for the comments.  How would I store each line as a variable from a longtext field within a database.  I could understand how this would be done from a text file, reading line by line, but I dont understand how I would read a line of a longtext field?
0
 
mhouldridgeAuthor Commented:
Sorted now. thanks!
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.