MySQL has a nice idiom for this, assuming that the "memberName" field in your "contest.forum" table has a uniqueness constraint (i.e. it is the "PRIMARY KEY" field, or it has "CONSTRAINT UNIQUE" attached to it), and this is enforced by the DB engine (I think this might only work for InnoDB type tables):
INSERT into forum (memberName,original) values (?,?)
on duplicate key update forum set current=? where memberName=?
(not tested -- look around for more info about the "on duplicate key update" syntax, and try it out).
So, I guess this isn't really a perl question after all, but if you wanted a perl solution instead (e.g. if the DB engine you're using appears not to enforce the uniqueness constraint), the idea would be to do a select first on the "contest" table for the given memberName value; if that returns a non-empty value, update the "current" field for that row; otherwise, insert a new row.
(If the process involves doing everyone in a single pass, it would be better to pull all the existing names from the "contest" db and hold those in a hash, then do updates or inserts for the new information, depending on whether a given name exists in the hash.)
update: better yet, do as ysth says below.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.