'\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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |