perlinacan has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use DBI; #my fledgling attempt at a Fantasy AFL comp #this file reads the downloaded weekly scores and inserts them #into a datbase #open the source file for weekly statistics my $weekly_file = shift || 'weekly'; # you can specify a team file on +the command # line or take the default #set variables for the database my $dsn="dbi:mysql:database=fflnew"; my $user="root"; my $pass=""; my $dbh = DBI->connect($dsn, $user, $pass) || die "Could not connect: $DBI::errstr\n"; open WEEKLY, "< $weekly_file" or die "Cannot open $weekly_file for +reading:$!"; while (<WEEKLY>) { my ($round,$playername,$kick,$handpass,$possess,$mark,$hitout,$tack +le,$freefor,$freeagainst,$goal,$behind) = ("","","","","","","","","" +,"","",""); ($round,$playername,$kick,$handpass,$possess,$mark,$hitout,$tack +le,$freefor,$freeagainst,$goal,$behind)= split( /,/ ); my $sth = $dbh->prepare("INSERT into ffl_weekly (score_ID,round,pla +yername,kick,handpass,posession,mark,hitout,tackle,freefor,freeagains +t,goal,behind,total) values (NULL,?,?,?,?,?,?,?,?,?,?,?,?,NULL)"); + + $sth->execute($round, +$playername,$kick,$handpass,$possess,$mark,$hitout,$tackle,$freefor,$ +freeagainst,$goal,$behind); #close and commit changes } close WEEKLY|| die "Cannot close $weekly_file, $!"; $dbh->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: checking to do a inser or update
by MrCromeDome (Deacon) on Jun 07, 2002 at 04:05 UTC | |
by zakb (Pilgrim) on Jun 07, 2002 at 09:56 UTC | |
by Abigail-II (Bishop) on Jun 07, 2002 at 11:22 UTC | |
|
Re: checking to do a insert or update
by graff (Chancellor) on Jun 07, 2002 at 04:48 UTC | |
by dsheroh (Monsignor) on Jun 07, 2002 at 15:44 UTC |