Just another Perl shrine | |
PerlMonks |
Avoid using a module if it's not availableby perfluffle (Initiate) |
on Jun 12, 2008 at 17:51 UTC ( [id://691741]=perlquestion: print w/replies, xml ) | Need Help?? |
perfluffle has asked for the wisdom of the Perl Monks concerning the following question:
Hi -
I've been knocking my head against this for hours now, and I can't seem to get it right. (v5.8.8 from Activestate on Windows XP).
I have a list of modules I want to use, but only if they're available (i.e. installed on the system the script is running on and included in @INC). If they're not available, I want the code that calls them to be skipped. Installing them isn't an option, period. Oh, how I wish it were, but it's not. Here is an example (line numbers added for clarity): My goals are: 1. Avoid a compile-time error when FOO::bar is unavailable. The "eval" in line 004 prevents this quite nicely. 2. Avoid a run-time error on line 010 when FOO::bar is available. I'm not doing so well with the second objective. Everything I've tried seems to result in a run time error like "Can't call method "zlot" without a package or object reference at foobarzlot.pl line 10." Yet, FOO:bar is right there on the development system and should return a valid "zlot" with no problem at all. If I put the use (or require) statement outside the eval, everything works perfectly. Unfortunately, having no influence on what's installed on the target system(s), it's virtually guaranteed that some systems will barf at compile time. P.S. If you replace FOO::bar with File::stat and zlot with size, you'll get a better idea. I just didn't want people to get hung up on the choice of module. I have about ten different modules I need to use or not-use based on availability.
Back to
Seekers of Perl Wisdom
|
|