Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: perl and mysql parse a text file

by rnahi (Curate)
on Feb 03, 2006 at 15:21 UTC ( #527678=note: print w/ replies, xml ) Need Help??


in reply to perl and mysql parse a text file

If your query requires one parameter, and you are passing an array, it's correct that only the first is inserted.

What you need is to prepare once aand execute many times.

my $sth = $dbh->prepare( "INSERT INTO data_profile (file) VALUES (?)") +; for (@array) { $sth->execute($_); }

Alternatively, you can create a multiple insert query.

# assume that @array contains qw(abc def ghi); my $query = 'INSERT INTO data_profile (file) VALUES '; $query .= join(',', map {'(?)'} @array); # now $query will be 'INSERT INTO data_profile (file) VALUES (?),(?),( +?)' $dbh->do($query, @array);

HTH


Comment on Re: perl and mysql parse a text file
Select or Download Code
Re^2: perl and mysql parse a text file
by Anonymous Monk on Feb 03, 2006 at 15:29 UTC
    this would create a separate DB row for each file row? Is it possible to store the entire file in a single row?

      Well, if you say "parse" a text file and then use an "@array", it seemed logical to assume that you wanted separate records.

      With this new piece of information at hand, Fletch's post meets your needs.

      I recommend you read this useful node and this insightful article (off site) before you post your next request.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527678]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-23 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls