Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: regexp for scalar containing a mixture of LF & CRLF

by Eimi Metamorphoumai (Deacon)
on Dec 09, 2004 at 23:05 UTC ( #413713=note: print w/ replies, xml ) Need Help??


in reply to regexp for scalar containing a mixture of LF & CRLF

I think what you want is

s/(?<!\r)\n/\r\n/;
The problem with your code is that you're trying to replace a single CR with an LF, so if you have an LF alone, it's unchanged. If you start with CRLF, you end up with LFLF, which isn't what you want. What you need to look for is an LF not preceded by CR, and replace it with CRLF.

Update: It appears I spoke a little too soon, and with too much Unix-centrism. The text was fine, but I forgot that "\n" in Perl changes meaning under different platforms. What you want is

s/(?<!\015)\012/\015\012/g;


Comment on Re: regexp for scalar containing a mixture of LF & CRLF
Select or Download Code
Replies are listed 'Best First'.
Re^2: regexp for scalar containing a mixture of LF & CRLF
by NateTut (Deacon) on Dec 09, 2004 at 23:59 UTC
    Thanks, but nope. See my next post for my ugly answer that finally worked.

    Doug

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2015-08-04 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (62 votes), past polls