in reply to Inserting the line references in a text file
my $statement = qq( INSERT INTO dickens VALUES ($word, $Line{$word}) );
No, don't do that. Use placeholders instead:
my $sth = $dbh->prepare('INSERT INTO dickens VALUES(?, ?)'); # and then, as often as you want: $sth->execute($line, $count);
I guess the database looks something like this:
CREATE TABLE dickens ( word VARCHAR(30), line INTEGER, );
If that's the case, you can't store multiple line numbers in one row. In that case you have to make multiple rows with the same word, or change the database layout.
foreach $word ( @theseWords ) { my @lines = split m/ ,/, $Line{$word}; for (@lines){ $sth->execute($word, $_); } }
Of course it's better to store the line numbers as arrays in the first place.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inserting the line references in a text file
by Quicksilver (Scribe) on Feb 27, 2008 at 11:05 UTC | |
by moritz (Cardinal) on Feb 27, 2008 at 11:10 UTC | |
by Quicksilver (Scribe) on Feb 28, 2008 at 08:37 UTC |