In the following code I want do a score update 3 times each weekend. At the moment I end up with 3 copies of the info in the database, I need it to overwrite whats there or insert new stuff, can't get it to do it, am I better using update or replace ? I am using mySQL btw
#!/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();

In reply to checking to do a insert or update by perlinacan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.