Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Help with CSV file parsing

by starX (Chaplain)
on Aug 05, 2008 at 08:32 UTC ( [id://702276]=note: print w/replies, xml ) Need Help??


in reply to Help with CSV file parsing

If the number of values that you need to be inserting in your query is fixed, and yu're using DBI, placeholders are the way to go.
# Code that connects to database my $sth = $dbh->prepare(' Insert into person_info VALUES(?,?,?)'); # Code that opens your file. while (<FILE>) { my @row = split /,/; $sth->bind_param(1, $row[0]); $sth->bind_param(2, $row[1]); $sth->bind_param(3, $row[2]); $sth->execute() or warn "Couldn't execute INSERT: $DBI::errstr\n"; }
Of course, this doesn't take into account the manipulation on the second field of your csv that it sounds like you need to do.

Hope that helps,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-19 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found