Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Problem locating Carp::Heavy

by Miguel (Friar)
on Apr 07, 2005 at 01:14 UTC ( #445500=perlquestion: print w/ replies, xml ) Need Help??
Miguel has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

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'.

Comment on Problem locating Carp::Heavy
Select or Download Code
Re: Problem locating Carp::Heavy
by jhourcle (Prior) on Apr 07, 2005 at 01:46 UTC

    um... you're missing Carp::Heavy?

    When you 'use Carp;', which a whole lot of modules do (such as DBI), it loads some lightweight functions. If you call one of those functions, they then do 'require Carp::Heavy;' to do the actual work. (so the bulky part of the code doesn't get loaded until it's really needed.)

    Once you have Carp::Heavy installed (which I would have expected to be at /usr/lib/perl5/5.8.6/Carp/Heavy.pm based on the message given), it should give you a message telling you what went wrong that caused Carp to be called.

      That was my first idea.

      But

      CPANPLUS::Shell::Default -- CPAN exploration and modules installation +(v0.053) *** Please report bugs to <cpanplus-bugs@lists.sourceforge.net>. *** Using CPANPLUS::Backend v0.053. *** ReadLine support available (try 'i Term::ReadLine::Perl'). CPAN Terminal> i Carp::Heavy [MSG] Checking if source files are up to date [MSG] Retrieving /root/.cpanplus/sourcefiles.2.13.stored [ERROR] 'Carp::Heavy' does not contain an author part [ERROR] Cannot find 'Carp::Heavy' in the module tree No such module: Carp::Heavy No modules found to operate on! Nothing done CPAN Terminal>

        Right ... I should've been more clear -- it's part of Carp. Reinstall Carp so you get Carp::Heavy. (which is of course, part of the main perl distribution, so this can get messy). As it's pure perl, you should be able to just extract Carp.pm and Carp/Heavy.pm from the distribution, and place them in the right place.

        (there might be some easy way to install Carp from CPAN, without needing to pull down the whole perl-5.8.6 tarball, but I have no idea how ... but maybe someone else on here does)

Re: Problem locating Carp::Heavy
by Errto (Vicar) on Apr 07, 2005 at 02:14 UTC

    I'm pretty sure Carp::Heavy is a core module, or at least it appears to be one in my distribution (Fedora Perl 5.8.3 RPM). So it sounds like there's something screwy in your Perl installation. You might need to refresh/reinstall Perl on your system. You can also search your system for the file Carp/Heavy.pm to see if it's there, but if you do find it don't just copy it into Perl's lib directory unless you're sure it's the right version.

    Of course, this is only coming into the picture because some module is trying to tell you something. So I would first try getting rid of RaiseError in your DBI call, and add

    or die $db->errstr;
    after your execute call.

      Thank you for your suggestion.

      I tried with:

      $db->{RaiseError} = 0; ... $sth->execute( $to || "-", $from || "-", $subject || "-", $date || "-", $body || "-", $headers || "-" ) or die $db->errstr;
      But I still got the same result.

      And seems I do have Carp::Heavy on my system:

      ~% slocate Heavy.pm /usr/lib/perl5/5.8.6/Carp/Heavy.pm /usr/lib/perl5/5.8.6/Exporter/Heavy.pm
      On the other hand, if I just do:
      #!/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 $sql = " INSERT INTO tabmail(para,de,assunto,data,corpo,cabecalho) VALUES(?,?,?,?,?,?) "; my $sth = $db->prepare($sql); for ( 1 .. 2000) { $sth->execute($_,$_,$_,$_,$_,$_) or die $db->errstr; }
      All records are stored fine.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://445500]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-26 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls