I have researched this on the Net for about a week now and after having some good and bad luck, have come to the Monks for their wisdom.

I am new to Perl and had never programmed anything until about a month ago. Additionally, I have no experience with SQL or databases in general, so please have patience.

I have a CSV file consisting of two values per line, a server name and a NIC driver version. I need to find the corresponding server name within an Access database and insert the driver value into the proper field in the same row.

When I run my script, I get the following errors:
Bareword found in conditional at C:\Perl\scripts\test\newer.pl line 43.
Use of uninitialized value in split at C:\Perl\scripts\test\newer.pl line 26.
Use of uninitialized value in concatenation (.) or string at C:\Perl\scripts\test\newer.pl line 33.
Use of uninitialized value in concatenation (.) or string at C:\Perl\scripts\test\newer.pl line 35. "DBD::ODBC::db prepare failed: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. (SQL-42000)(DBD: st_prepare/SQLPrepare err=-1) at C:\Perl\scripts\test\newer.pl line 36.
Can't call method "execute" on an undefined value at C:\Perl\scripts\test\newer.pl line 37."

here is my amateur code:

#! c:\perl\bin\perl.exe -w # # InsertDrivers.pl #Importations and Declarations use Win32::ODBC; use DBI; my $DSN='Database'; my $field1='server'; my $field2='nic1_drv_version'; my ( $dbh, $sth1, $sth2, $vals, $driver, $servlist, $row, $sqlstatement1, $sqlstatement2, @row); #Open file for reading open(INPUT,"file.txt") || die; while (INPUT) { my ($servlist, $driver)=split(/,/); #Connect to database my $dbh=DBI->connect("dbi:ODBC:$DSN", "admin", "") or die "$DBI::e +rrstr\n"; $sqlstatement1=("SELECT server, nic1_drv_version FROM Servers"); $sth1=$dbh->prepare($sqlstatement1); $sth1->execute || die; @row=$sth1->fetchrow_array(); foreach ("$row\n" eq "$field1\n") { $sqlstatement2=("INSERT INTO Servers ($field2) VALUES ($dr +iver)"); $sth2=$dbh->prepare($sqlstatement2); $sth2->execute || die; } close (INPUT); $sth1->finish; $sth2->finish; $dbh->disconnect; }
Any suggestions will be greatly appreciated.

2003-04-16 edit ybiC: replace square bracket chars with appropriate html entities, to eliminate unintended PM links


In reply to Updating Specific Fields in MS 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.