Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: catching \n

by tedrek (Pilgrim)
on Aug 07, 2003 at 01:20 UTC ( #281675=note: print w/replies, xml ) Need Help??


in reply to catching \n

You are probably looking for /g, substitute globally. Your example will only get the first \r and \n in $blah. Just use something like this which will also handle DOS style returns

$blah =~ s/\r?\n/<br>/g;

Replies are listed 'Best First'.
Re2: catching \n
by bbfu (Curate) on Aug 07, 2003 at 01:38 UTC

    Or, if you want to be really portable, you could use s/\r?\n|\n?\r//g. That should catch most every platform's newline style, IIRC.

    bbfu
    Black flowers blossom
    Fearless on my breath

      If the web client (browser) doesn't use ASCII "\r\n"1 for newline in the text it sends to you, then the web client is broken, IMHO.

      1Note that this is not ambiguous. I know that "\r\n" on old Macs results in ASCII "\n\r", but that is because those Macs are near-ASCII systems despite them claiming to be ASCII systems. q-:

                      - tye

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://281675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2021-09-28 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?