# This code assumes that you've already initialized a
# database handle, $dbh, and your string of data is in
# $input
my $sth = $dbh->prepare('INSERT INTO my_table (field1, field2, field3)
+ VALUES (?, ?, ?);');
my @records = split '&', $input;
foreach my $record (@records) {
my @fields = split '\|', $record;
$sth->execute(@fields);
}
If there are only two fields in the record, the database placeholders (the ?s in the SQL text) should convert the nonexistent third element of @fields into a NULL in the database. If you get an error about not having enough values to bind, replace both occurrences of @fields with ($field1, $field2, $field3) to force it to always pass three values. (The code is untested, but simple enough that I should have gotten it right...)
Note the backslash escape in the second split. The | character is special and you'll get every character individually if you split on '|' instead of '\|'. | [reply] [d/l] [select] |