well... first you need an array of field names for the data...
I will assume the second number ie the 36 in ( 169 , 36 ) is the column (field specifier) and the first number IE 169 is the row number, and that you put the field names in an array @field_names. With that I would do the following...
my $oldrow;
my(@fields,@values);
while(<DATA>) {
chomp;
my ($row,$col,$data) = /^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*=>(.*)$/;
# that puts the row number in $1, col number in $2 and data in $3, a
+nd in the variable respectively
if($oldrow != $row) {
if(@fields) { #make sure there is data
$query = "INSERT INTO tablename(".(join ',', @fields)." VALUES("
+.(join ',', @values).')';
... do DB calls ...
@fields = @values = ();
}
$oldrow = $row;
}
push @fields, $field_names[$col]; # field name with proper data
push @values, db->quote($data); #run data through DB quoter
}
so you go through, adding data to @fields and @values in order so they
match up, then when you come to a new row number, you build your query (works with MySQL, think it will work in others) and execute it, then clear the fields and values and go onto next row.
Hope that is clear enough
- Ant
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.