what have you tried so far?

and which of the records with duplicate first fields do you want to insert into the database? i don't quite understand why you're doing this, perhaps you need to rethink your database structure. as it stands, there are a few options.

i can help you with the pseudocode:

== as always, use strict and -w
== of course, use DBI for the database interface
== create an empty hash to store unique keys
== create an empty array for data to process
== for each data line: == | use split with'|' on line, store values in temp array
== | is first value from the array (temp_array[0]) in unique hash?
== | | yes : dump temp array and move on
== | | no : add first value to unique hash, add array to data_to_process array
== for each array in data_to_process array
== | add to database

this assumes you want to keep the first line with a repeated first field. if you want to keep the last line, the logic will have to change appropriately.

~Particle


In reply to Re: VVP asks Unique field data? by particle
in thread VVP asks Unique field data? by Anonymous Monk

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.