splitting cvs file and insert in mysql via DBI

From: Xaver Biton (javier_at_t-online.de)
Date: 05/31/04


Date: Mon, 31 May 2004 12:44:24 +0200

Hi,

I'm running activestate 5.8 on winmaschine and I'm not very familiar
with perl but I like it very much.

Please be patient.

I've to split a csv file and insert it in a mysql db. I've done some
tests with other file and it worked wonderfull now in the real work
doesn't work, I' ve many errors.

The first question ist: why does perl complain when it find a "@" a "."
or a number in csv file. Perl says that it find an a number or a dot
... where opeator is espected. how can I get rid of this?

The second question which I can't anderstand it at all is, when I
execute the script and give the csv file as parameter I recieve this
error message:

Can't locate object method "Ilzasname" via package "Asan" (perhaps you
forgot to load "Asan"?) at customers.csv line 1.
*** Process "C:\Perl\bin\perl.exe" terminated. Return code=255

the csv file is like this:

100742;ASAN;Herr;Ilzasname Asan;Steingoetter-Greiff-StrDOT
;69168;Wiesloch;;;20020425;
10074;ASAN;Herr;Ilzasname Asan;Steingoetter-Greiff-StrDOT
;69168;Wiesloch;;;20020425;hansgkoenigetaolDOTcom;
100744;ASAN;Herr;Ilzasname Asan;Steingoetter-Greiff-StrDOT
;69168;Wiesloch;;;20020425;

hier is the perl script:

use DBI;
#use strict;

    # Declare and initialize variables
    my $host = 'localhost';
    my $db = 'dbname';
    my $db_user = 'username';
    my $db_password = 'password';

   $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password",
       {RaiseError => 0, PrintError => 0} );

   $sth = $dbh->prepare("INSERT INTO test(vo_nr, interne_customer_id,
nikname, salutation, name, forename, address, zip, city, tel, telefax,
customer_since, mail) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");

   while(<>){
          chomp;
          my ($interne_customer_id, $nikname, $salutation, $name, $address,
$zip, $city, $tel, $telefax, $customer_since, $mail) = split /;/;
          ($name,$forename) = split(/\s+/,$name);
          my $vo_nr = '012345';
          $sth->execute($vo_nr, $interne_customer_id, $nikname, $salutation,
$name, $forename, $address, $zip, $city, $tel, $telefax,
$customer_since, $mail);
   }

Thks. for help.

Xaver



Relevant Pages

  • Re: splitting cvs file and insert in mysql via DBI
    ... > or a number in csv file. ... Perl says that it find an a number or a dot ... How, *exactly*, are you calling this script? ... That error message would ...
    (comp.lang.perl.misc)
  • Question about creating variables from a CSV file
    ... done with PERL that I don't want somebody to do with Excel or Miserable ... The part I can't seem to get going has to do with making variables out ... of the header row in the CSV file. ... write the output to a new CSV file. ...
    (perl.beginners)
  • Re: Arrays, Dates, Indexing and Initialisation
    ... I have read Beginning Perl and a bit of Intermediate Perl, though was able to solve individual problems, but I was not sure,if I can code myself out of a wet paperbag. ... There is a date column in that csv file ... You should use common patterns where possible so that your code will be easier to understand. ...
    (perl.beginners)
  • Re: Hard or Easy? To find string, then grab criterion matched lines above and below?
    ... Here is my perl script solution so far - at the end of this post. ... I have replaced your paralell hashes by a has containing records. ... into the CSV file, ie. "Checking Netmeeting - Disable Remote Desktop ... You managed to pull out the CSR with a pattern. ...
    (comp.lang.perl.misc)
  • Re: splitting cvs file and insert in mysql via DBI
    ... Xaver Biton wrote: ... Perl says that it find an a number or a dot ... It could be that some fields now in the csv file are empty? ... exists a variable in the execute statement for every value (also the ...
    (comp.lang.perl.misc)