Samn has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: replacing /n
by BeernuT (Pilgrim) on Mar 23, 2002 at 04:49 UTC
    s/\n/<br>/g;
    works for me. Perhaps your working with a file that uses '\r\n' as the end of line feed ( windows ) in which you might want/need something like

    s/\r\n/<br>/g;

    PS: no need for the /i modifier as \n is not equal to \N
    Let me know if that still doesnt help.

    -bn
      Actually I've taken to using s/\r?\n/<br>/g lately. Data from textareas on IE seems to come in with the \r\n combo. But this regexp works right either way.

      -pete
      "I am Jack's utter lack of disbelief"

        Actually I've taken to using s/\r?\n/
        /g lately.

        That will handle Dos/Windows and Unix-like linebreaks, but not Macintosh linebreaks.

        s/\r\n?|\n/<br>/g; # Actually, this one's better: s/\015\012?|\012/<br>/g;

        U28geW91IGNhbiBhbGwgcm90MTMgY
        W5kIHBhY2soKS4gQnV0IGRvIHlvdS
        ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
        geW91IHNlZSBpdD8gIC0tIEp1ZXJk
        

        Actually, and correct me if I am wrong on this, but I believe the \n matches \r carriage returns as well as just simple newlines in perl 5. Could be wrong, but I think I am not :).

        Tradez
        "Never underestimate the predicability of stupidity"
        - Bullet Tooth Tony, Snatch (2001)
    153727
    by Samn (Monk) on Mar 23, 2002 at 04:56 UTC