Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
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
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 examining the Monastery: (6)
As of 2014-04-17 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls