'\n' eq '\\n'; they are both two characters, a backslash (\) followed by the letter en (n). When you use placeholders, passing '\n' in as a value acts the same as putting a literal '\\n' into the SQL (at least for SQLs where '\\' is how you get a single backslash character).

"\n" is a newline. When you use placeholders, passing "\n" in as a value acts the same as either putting '\n' (on some databases) or '
'
(a literal newline between single quotes) into the SQL.

It sounds like all you need is s/\r\n/\n/g (unless you need to run your script on old Macs, in which case you want something ugly like:

my( $cr, $lf )= ( "\r", "\n" ); ( $cr, $lf )= ( "\n", "\r" ) if "\r" eq "\x0a"; # On an old Mac ... s/$cr$lf/$lf/g;

or you can just ignore the currently even rarer possibility of non-ASCII Perl and do s/\x0d\x0a/\x0a/g, but I refuse to go back to the "hard code character encodings" school of programming even if the current thinking is that Unicode will be the one ring to rule them all forever... eventually).

- tye        


In reply to Re^3: Line separators when passing multi-line fields to a database ("\n") by tye
in thread Line separators when passing multi-line fields to a database by davies

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.