in reply to Substituting Newline Characters

Yes. $comments =~ s/\n/<.br>\n./g;

Why you'd want to is beyond me, though.

edit:
I see now. You need this $comments =~ s/\n/<br>\n/g;

Explanation: The g modifier specifies you want to substitute all matches instead of just the first one.

Ps: you can use <code> tags to type code with worrying about escaping < characters.

Edit2: I usually find it much easier on the users to do this instead: s/\n\n/<p>\n/g; and leave the single breaks alone.

Replies are listed 'Best First'.
Re: Re: Substituting Newline Characters
by BUU (Prior) on Mar 15, 2004 at 23:11 UTC
    (Responding to edit2) Wouldn't that produce something like
    this is a line <p> this is another line <p> this is a third line <p>
    How ugly. Paragraph tags aren't line breaks, they're supposed to enclose a paragraph! At least do s/\n\n/<\/p><p>/g and do something to insert a paragraph tag at the beginning.