in reply to creating a SQL statement from an array
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 enoughmy $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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: creating a SQL statement from an array
by JSchmitz (Canon) on Apr 16, 2001 at 21:42 UTC |