lestrrat has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to include an external file on the fly from within some perl code, and I would also like to catch any "require" errors as well.

However, doing

eval{ require $somefile; }; if( $@ ) { print $@; }

only shows the top level error ( such as "Compilation failed in require at /foo/bar.pl" ). I want more detailed message, like "Global symbol $foo requires explicit package name at /blah.pl" type of messages as well.

How can I capture these messages from within Perl?

Replies are listed 'Best First'.
Re: Capturing detailed error messages on 'require failure
by chromatic (Archbishop) on May 22, 2001 at 08:08 UTC
    I get the same results as tye on 5.5.3, so it's not changed between the two versions.

    Perhaps you don't have strict in package scope in your required file? That's my only guess, unless you're not running from the command line.

(tye)Re: Capturing detailed error messages on 'require failure
by tye (Sage) on May 22, 2001 at 05:07 UTC
    eval { require foo}; print $@ Global symbol "$foo" requires explicit package name at foo.pm line 3, +<IN> line 1. Compilation failed in require at (eval 4) line 2, <IN> line 1.

    This is Perl 5.6.0. That is how I've always understood that it was supposed to work so I'm not sure why it isn't working that way for you.

    Perhaps knowing this will help you track down more details on the source of the problem you are having.

            - tye (but my friends call me "Tye")