in reply to Re: problem with 'bare LF' in script
in thread problem with 'bare LF' in script

Thank you, Grandfather, but that did not work...

Still trying solutions if you know of anything else, I'd appreciate it.

thx,
Richard

Replies are listed 'Best First'.
Re^3: problem with 'bare LF' in script
by monarch (Priest) on Nov 12, 2008 at 00:57 UTC
    No idea if this will help:
    $str =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg;
    where \r is a carriage-return and \n is a line-feed. This code will convert every type of line ending to a CR-LF pair.

    Update: removed parenthesis from replacement text

      See the Newlines section in perlport for why using \r and \n is a bad idea™ in this sort of context.


      Perl reduces RSI - it saves typing

        I've read:

        A common misconception in socket programming is that \n eq \012 everywhere. When using protocols such as common Internet protocols, \012 and \015 are called for specifically, and the values of the logical \n and \r (carriage return) are not reliable.

        before, and stuff around it, and I still don't understand :-(

        Is this telling me that when Perl interpolates the string "\r\n" that it may use some other values for the two escapes ? If so, where ? I've not been able to catch it doing that, but I have only got Winders and LINUX to go on. Does "\n" interpolate to "\x0D" on a Mac ?

        I understand that IO layers may translate "\x0A" bytes to and from "\x0D\x0A" pairs and vice versa. I guess there's similar support for "\x0D" line-endings (though I haven't found it). I can see that means that if you think of "\n" as interpolating to a local system newline, you may be disappointed. But that's not the same as "\n" interpolating to something different in different places or at different times.

        Desperately seeking enlightenment....