I have written the below Perl script to extract data from a pipe delimited text file to an Access database.

I am currently running this script from a batch file which has a single statement: perl perlscript2.txt where perlscript2.txt is the pipe delimited text file which looks like this:

1009087|10/02/03|abbcdef|1124567|5679.34 1998023|12/06/02|rrrasdd|7468758|300.78
I keep getting an error message: 'DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement'


My code looks like this:

# !/usr/bin/perl -w use DBI qw(:sql_types); use DBD::ODBC; $dsn = "dbi:ODBC:Daily_Rec"; $dbh = DBI->connect($dsn,' ',' ', {RaiseError=>1,PrintError=>1,AutoCommit=>1} ); open(DAT, "c:/Temp/heldreceipts_TempFile.txt") || die "could not open Held Receipts file"; while(<DAT>) { chomp; @line = split(/\|/, $_); $var1=$line[0]; $var2=$line[1]; $var3=$line[2]; $var4=$line[3]; $var5=$line[4]; $var6=$line[5]; $var7=$line[6]; $var8=$line[7]; $query=qq{insert into Held_Receipts values (?,?,?,?,?,?,?,?)}; $sth = $dbh->prepare($query) or die "cannot prepare query"; $sth->execute($var1, $var2, $var3, $var4, $var5, $var6, $var7, $var8) or $DBI::err and die $DBI::errstr; } $sth->finish(); $dbh->disconnect();

when I print out $dbh i get HASH along with numbers in brackets (which means the $dbh part works fine right?).

Any help on resolving this issue will be greatly appreciated!!! Thanks!

update (broquaint): added <code> tags


In reply to Extracting data from a pipe delimited text file into a table in Access by Anonymous Monk

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.