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
    Hi Moritz,
    Thanks for the pointers on the database. I am trying to split the lines so that each occurence of the word will have a separate line number as there is to be an extension to this work which requires them to be separate lines.
    Printing the data shows that it is printing out:
    yourself: 1791, 1792, 2440
    but what I'm trying to get is
    yourself: 1791
    yourself: 1792
    yourself: 2440
    to accommodate the creation of the new column later.
      That's what my last example inserts into the DB, isn't it?

      You can use the same schema to print it, of course.

        Figured it out, muppet here inserted a space in between m/ ,/ rather than having m/,/. Thanks for all your help Moritz.