#!/usr/bin/perl
use strict;
use DBI;
#configurables
my $workdir = "./work";
my $roster = "";
my $dbh = DBI->connect("DBI:mysql:database=esms",
'username',
'password',
) or die "Can't connect to database";
my @fields = qw (player_name player_age player_nat player_prs player_s
+t
player_tk player_ps player_sh player_stamina
player_aggression player_kab player_tab player_pab
player_sab player_games player_sav player_ktk player_
+kps
player_sht player_gls player_dpoints player_inj playe
+r_sus
player_fit);
my $fieldlist = join ", ", @fields;
my $field_placeholders = join ", ", map {'?'} @fields;
my $insert_query = qq{
INSERT INTO employees ( $fieldlist )
VALUES ( $field_placeholders )};
my $sth= $dbh->prepare( $insert_query );
opendir DIR, $workdir;
@files = grep /ja/, readdir DIR;
closedir DIR;
foreach (@files) {
$roster = $_;
print"now processing $roster\n";
open (RF,"./work/$roster");
open (UNL,">./work/$roster.unl");
while (<RF>) {
chomp;
next if m/^Name/;
next if m/----/;
print "$_\n";
$_ =~ s/\s+/|/g;
my @player_rec = split '|';
if ($sth->execute(@player_rec)) {
print "Worked, cool";
}
else {
print "Didn't work, uncool, error is: $DBI::errstr";
}
print UNL "$_\n";
}
close(RF);
close(UNL);
}
Resulting Errors:
Didn't work, uncool, error is: called with 71 bind variables when 24 a
+re neededZ_Otyusyo|24|ire|R|3|5|11|5|55|21|300|300|300|300|0|0|0|0|0|
+0|0|0|0|0|100|
DBD::mysql::st execute failed: called with 74 bind variables when 24 a
+re needed at ./planb.pl line 45, <RF> line 17.
Didn't work, uncool, error is: called with 74 bind variables when 24 a
+re neededP_Choonduaga|25|cam|R|3|7|10|7|57|35|300|300|300|300|0|0|0|0
+|0|0|0|0|0|0|100|
DBD::mysql::st execute failed: called with 77 bind variables when 24 a
+re needed at ./planb.pl line 45, <RF> line 18.
Didn't work, uncool, error is: called with 77 bind variables when 24 a
+re neededV_Itroidro|19|ita|LC|3|5|10|7|42|24|300|300|300|300|0|0|0|0|
+0|0|0|0|0|0|100|
DBD::mysql::st execute failed: called with 76 bind variables when 24 a
+re needed at ./planb.pl line 45, <RF> line 19.
Didn't work, uncool, error is: called with 76 bind variables when 24 a
+re neededK_Ogoejheb|23|jap|C|3|9|9|8|45|28|300|300|300|300|0|0|0|0|0|
+0|0|0|0|0|100|
and so on.......