Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Its a case of if certain facilities are available, then I would like to use them and if not then I will get by without. Sometimes there is more than one module available to do something and I want my code to work with either and not fall over if my particular favourite is missing. The above works fine if I can use require, but not all modules will work with a simple require. What is the recomended way to code this and still be able to utilise a "use" statement?my $souperdouper=0; eval { require "SuperDouperPrinter" } and $superdouper=1; if ($souperdouper) { SouperDouperPrinter::Print($something); } else { print $something; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I catch a failure of use?
by McA (Priest) on Oct 14, 2014 at 11:29 UTC | |
by syphilis (Archbishop) on Oct 14, 2014 at 12:00 UTC | |
by McA (Priest) on Oct 14, 2014 at 13:42 UTC | |
by syphilis (Archbishop) on Oct 15, 2014 at 00:20 UTC | |
|
Re: How can I catch a failure of use?
by Discipulus (Canon) on Oct 14, 2014 at 11:09 UTC | |
|
Re: How can I catch a failure of use?
by Athanasius (Archbishop) on Oct 14, 2014 at 12:10 UTC | |
|
Re: How can I catch a failure of use? (by not catching it)
by Anonymous Monk on Oct 14, 2014 at 10:49 UTC | |
|
Re: How can I catch a failure of use?
by Anonymous Monk on Oct 14, 2014 at 12:35 UTC |