#!/usr/bin/perl use DBI; $|=1; $dbh = DBI->connect("dbi:Pg:dbname=search", "", "", { AutoCommit => 1, }) or die "cannot connect to database!"; $insert_word = $dbh->prepare("INSERT INTO word (word, docpos) VALUES (?, ?)") or die "cannot prepare 1"; $insert_doc = $dbh->prepare("INSERT INTO doc (doc_id, ri, n_words, n_chars) VALUES (?, ?, ?, ?)") or die "cannot prepare 2"; $next_doc_id = $dbh->prepare("SELECT NEXTVAL ('seq_doc')") or die "cannot prepare 3"; open FILE, "files"; for $line () { print $line; ($file_index, $ri, $n_chars, $n_words) = split " ", $line; $next_doc_id->execute or die "cannot get next doc_id"; ($doc_id) = $next_doc_id->fetchrow_array; $doc_id == $file_index or die "seq_doc not working"; $insert_doc->execute($doc_id, $ri, $n_chars, $n_words) or die "cannot execute insert doc"; } open FILE, "index"; for $line () { print $line; ($word, $docpos) = split " ", $line, 2; print length $docpos, "\n"; if (length $docpos < 8000) { $insert_word->execute($word, $docpos) or die "cannot execute insert word"; } }