Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: How to store the indexes of a arrayby flexvault (Monsignor) |
on Oct 14, 2011 at 10:44 UTC ( [id://931472]=note: print w/replies, xml ) | Need Help?? |
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:
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):
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 Section
Seekers of Perl Wisdom
|
|