[Pdx-pm] sqlite and chomp
Daniel Herrington
dherrington at robertmarktech.com
Thu Apr 29 23:42:37 PDT 2010
All,
I'm parsing through an array that was produced by slurping a file. One
of the first things I do in the array is chomp the line to remove the
newline character. I then do an insert into a sqlite table:
while (@caJIL) {
my $line = shift(@caJIL);
chomp($line);
my ($jc,$jv) = split (':',$line);
if ($jc =~ /insert_job/) {
$jv = substr $jv, 1;
my $sth = $dbh->prepare_cached("INSERT INTO atJobs
(jobName) VALUES (?)");
$sth->execute($jv);
}
....
}
However, the chomp seems to be doing something funny to the line that
sqlite doesn't like. Here is the output of a select on the table with
the chomp:
dan at blackswan:~/Documents/RobertMark/BofA/work/foo/VA2$ sqlite3 VA2-bofa.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> select * from atJobs;
||||||||||||||||||||||||||||||||||||||||||||||||||||
sqlite> .quit
And here is the output without the chomp:
dan at blackswan:~/Documents/RobertMark/BofA/work/foo/VA2$ sqlite3 VA2-bofa.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> select * from atJobs;
1|WCM_WGCIB_MON_FW_1
||||||||||||||||||||||||||||||||||||||||||||||||||||
sqlite> .quit
I looked at the file in binary, and the line ends with a 0D 0A, which is
CR/LF? If so, shouldn't perl simply look at it as a \n and move along?
If I run the perl oneliner:
perl -pi -e 's/\r\n/\n/g' file.txt
against the file and then run my script, everything works fine. Isn't
chomp supposed to remove the \r\n?
thanks,
--
Daniel B. Herrington
Director of Field Services
Robert Mark Technologies
dherrington at robertmarktechnologies.com
o: 651-769-2574
m: 503-358-8575
More information about the Pdx-pm-list
mailing list