Miguel has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to insert about ~5000 records into a Postgres (v. 8.0.1) database.
This is a simple program that reads MailDir dirs, opens each mail, extracts some parts from it and saves it into the database.
#!/usr/bin/perl -Tw use diagnostics; use strict; use IO::All; use DBI; my $db = DBI->connect( "dbi:Pg:dbname=db;", "user", "password" ) or die( "error message ..." ); $db->{RaiseError} = 1; $db->{pg_server_prepare} = 1; $db->{AutoCommit} = 1; my @MAILDIRS = ( '/path/to/maildir/1/', '/other/path/to/maildir/2/', ); my $sql = " INSERT INTO tabmail(para,de,assunto,data,corpo,cabecalho) VALUES(?,?,?,?,?,?) "; my $sth = $db->prepare($sql); my $i = 0; foreach my $dir (@MAILDIRS ) { for my $mail ( io($dir)->all ) { print "\n", $i, ": ",io($mail)->filename,"\n"; my $flag = 0; my ($headers,$body); my ($from, $to,$date,$subject); foreach my $linha ( io($mail)->getlines ) { $from = $linha if $linha=~/^From: .*/; $to = $linha if $linha=~/^To: .*/; $date = $linha if $linha=~/^Date: .*/; $subject = $linha if $linha=~/^Subject: .*/; if ( $linha =~/[^\n].*/ && $flag != 1 ) { $headers .= $linha, } elsif ($linha=~/^\n/ && $flag != 1) { $flag =1; } else { $body .= $linha; } } $sth->execute( $to || "-", $from || "-", $subject || "-", $date || "-", $body || "-", $headers || "-" ); $i++; } }
All runs fine (records are stored) until 1017 records. Then stops with:
+----------------Record number | +----------File name 1017: 1911 Can't locate Carp/Heavy.pm in @INC (@INC contains: /usr/lib/perl5/5.8.6/i486-linux /usr/lib/perl5/5.8.6 /usr/lib/ +perl5/site_perl/5.8.6/i486-linux /usr/lib/perl5/site_perl/5.8.6 /usr/ +lib/perl5/site_perl) at /usr/lib/perl5/5.8.6/Carp.pm line 255, <GEN73 +27> line 77 (#1) (F) You said to do (or require, or use) a file that couldn't be found. Perl looks for the file in all the locations mentioned in @ +INC, unless the file name included the full path to the file. Perhaps +you need to set the PERL5LIB or PERL5OPT environment variable to say w +here the extra library is, or maybe the script needs to add the library + name to @INC. Or maybe you just misspelled the name of the file. See perlfunc/require and lib. Can't locate Carp/Heavy.pm in @INC (@INC contains: /usr/lib/perl5/5.8. +6/i486-linux /usr/lib/perl5/5.8.6 /usr/lib/perl5/site_perl/5.8.6/i486 +-linux /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl) at /u +sr/lib/perl5/5.8.6/Carp.pm line 230, <GEN7327> line 77.
No matter what email is at that position (1017). Always crashes with the same error message.
What am I missing here?
Thank you,
Miguel
Retitled by BazB from 'Inserting 1000s of records in a database'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem locating Carp::Heavy
by Errto (Vicar) on Apr 07, 2005 at 02:14 UTC | |
by Miguel (Friar) on Apr 07, 2005 at 03:06 UTC | |
|
Re: Problem locating Carp::Heavy
by jhourcle (Prior) on Apr 07, 2005 at 01:46 UTC | |
by Miguel (Friar) on Apr 07, 2005 at 01:58 UTC | |
by jhourcle (Prior) on Apr 07, 2005 at 02:31 UTC |