I want to get some info from an error that I get when I try to load a module, so I tried this:
eval { use Cache::File; };
But, it didn't stop the error from killing the program.

Update Added readmore tags.

It's this kind of error:
/usr/lib/dld.sl: Can't shl_load() a library containing Thread Local Storage: /usr/lib/libpthread.1 /usr/lib/dld.sl: Exec format error Can't load '/usr/local/perl-5.8.7/lib/5.8.7/PA-RISC2.0/auto/DB_File/DB_File.sl' for module DB_File: Exec format error at /usr/local/perl-5.8.7/lib/5.8.7/PA-RISC2.0/XSLoader.pm line 68. at /usr/local/perl-5.8.7/lib/5.8.7/PA-RISC2.0/DB_File.pm line 251 Compilation failed in require at /usr/local/perl-5.8.7/lib/site_perl/5.8.7/Cache/File/Heap.pm line 29. BEGIN failed--compilation aborted at /usr/local/perl-5.8.7/lib/site_perl/5.8.7/Cache/File/Heap.pm line 29. Compilation failed in require at /usr/local/perl-5.8.7/lib/site_perl/5.8.7/Cache/File.pm line 26. BEGIN failed--compilation aborted at /usr/local/perl-5.8.7/lib/site_perl/5.8.7/Cache/File.pm line 26. Compilation failed in require at ./tryCache line 6. BEGIN failed--compilation aborted at ./tryCache line 6.

Now, my question is not how to fix the error, but is there something like eval, some trick, some procedure that will let me capture the error from the use statement and go on to take remedial action based on the error?
Do I have to launch a separate process and capture the STDERR?

Now here's the background:
My fix looks like this

# fix for Cache::File BEGIN { if (!defined($ENV{LD_PRELOAD})) { $ENV{LD_PRELOAD} = '/usr/local/perl-5.8.7/lib/5.8.7/PA-RISC2.0 +/auto/DB_File/DB_File.sl'; my $me = "export LD_PRELOAD='$ENV{LD_PRELOAD}' && $0"; {exec $me} print STDERR "couldn't exec $me\n"; } elsif ($ENV{LD_PRELOAD} =~ /DB_File.sl/) { print "LD_PRELOAD is $ENV{LD_PRELOAD}\n"; } else { $ENV{LD_PRELOAD} = '/usr/local/perl-5.8.7/lib/5.8.7/PA-RISC2.0 +/auto/DB_File/DB_File.sl'.":$ENV{LD_PRELOAD}:" ; my $me = "export LD_PRELOAD='$ENV{LD_PRELOAD}' && $0"; {exec $me} print STDERR "couldn't exec $me\n"; } }
Now I'm OK with this, but I'd like to make it resilient to changes in perl or module location/version, so I'm thinking, capture the error output, get the location of the shared library and then put the variable in my BEGIN block.

andyford
or non-Perl: Andy Ford


In reply to stronger than eval? by andyford

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.