Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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);


Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527678]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2018-06-22 18:02 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.