in reply to Inserting data in Mysql
A few notes:
#!perl use strict; use warnings; use File::DosGlob 'glob'; use DBI; use DBD::mysql; my $dir = "/user/data/"; $database = userdata; $dbh = DBI->connect('dbi:mysql:userdata','root','') or die "Connection Error: $DBI::errstr\n"; my $sth = $dbh->prepare(<<EOSQL) or die "Can't prepare insert statement: $DBI::errstr\n"; INSERT into userdata(id, name, age, address) values (?, ?, ?, ?) EOSQL chdir $dir; for my $file (grep {-f} glob '2010-05*') { open my $fh, '<', $file; while (<$fh>) { my ($id) = /\bid=(\d+)/; next if not defined $id; # Can't store without a key! my ($name) = /\bname=("(.*?)")/i; my ($age) = /\bage=(\d+)/; my ($add) = /\baddress=("(.*?)")/i; $sth->execute($id, $name, $age, $add) or die $DBI::errstr; } }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inserting data in Mysql
by locked_user sundialsvc4 (Abbot) on Dec 03, 2010 at 13:44 UTC |