Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This script is not inserting all values of corresponding fields in mysql database.#!perl #use strict; #use warnings; use File::DosGlob 'glob'; use DBI; use DBD::mysql; my $dir = "/user/data/"; my @data; $database = userdata; $dbh = DBI->connect('dbi:mysql:userdata','root','') or die "Connection + Error: $DBI::errstr\n"; chdir $dir; for my $file (grep {-f} glob '2010-05*') { open my $fh, '<', $file; while (<$fh>) { if (my ($id) = /\bid=(\d+)/) { push @ids, $id; } if (my ($name) = /\bname=("(.*?)")/i) { push @names, $name; } if (my ($age) = /\bage=(\d+)/) { push @ages, $age; } if (my ($add) = /\baddress=("(.*?)")/i) { push @adds, $add; } } $ids1 = join(' ',@ids); $name1 = join(' ',@names); $age1 = join('',@ages); $add1 = join('',@adds); $query = "INSERT into `userdata` ( `id`, `name`, `age`, `address`) val +ues ('$id1', '$nam1', '$age1', '$add1')"; $dbh->do($query); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inserting data in Mysql
by marto (Cardinal) on Dec 03, 2010 at 10:41 UTC | |
by moritz (Cardinal) on Dec 03, 2010 at 10:58 UTC | |
|
Re: Inserting data in Mysql
by roboticus (Chancellor) on Dec 03, 2010 at 11:41 UTC | |
by locked_user sundialsvc4 (Abbot) on Dec 03, 2010 at 13:44 UTC | |
|
Re: Inserting data in Mysql
by JavaFan (Canon) on Dec 03, 2010 at 11:07 UTC | |
|
Re: Inserting data in Mysql
by samarzone (Pilgrim) on Dec 03, 2010 at 11:36 UTC | |
by Anonymous Monk on Dec 03, 2010 at 11:47 UTC | |
|
Re: Inserting data in Mysql
by ww (Archbishop) on Dec 03, 2010 at 14:35 UTC |