I'm reading into your question, but I have a script that downloads a CSV file with about 50 fields per record and then parses it to add records to a Berkeley DB. Unfortunately, every once in a while, the producer of the CSV file changes or worse adds a field in the middle of the record. My solution was to add a file:

date 1 Account 19 Client 4 Address 1 5 Address 2 6 . . .

Note: The "Account \t 19" is just to show key and index don't have to be in sequential order.

The script reads this file into a hash where the first field is the column heading and second field is the index into the DB array (example code is untested):

my %hash = (); my @array = (); my $no = 0; while (<$Fields>) { my $var = $_; chomp($var); my ( $key, $index ) = split(/\t/,$var); $hash{ $key } = $index; $array[$no] = $key; $no++; }

The script then parses the first record(keys in hash) of the CSV file to verify all fields are in the same order as the $array and that nothing has changed. If something has changed, the script emails me but doesn't corrupt the DB. I then modify the above file to conform to the new data format. The file is the order of the input fields and the index is the location in the array that is written to the DB. If a new field has been added in the middle, I place it in key order in the file and the index is the next element at the end of the array.

Once the key order is verified the script then processes the actual data and updates the DB.

I hope this is similar to your problem.

Good Luck

"Well done is better than well said." - Benjamin Franklin


In reply to Re: How to store the indexes of a array by flexvault
in thread How to store the indexes of a array by anonym

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.