http://qs321.pair.com?node_id=1210479


in reply to Help Changing use into require/import

UPDATE: This *could* be bad advise, see the reply node at Re^2: Help Changing use into require/import by stevieb.

The way I do this, certainly there are other ways:

my $HAVE_Capture_Tiny = 0; eval "use Capture::Tiny qw(capture)"; if ( !$@ ) { $HAVE_Capture_Tiny = 1; } ... if ( $HAVE_Capture_Tiny ) { my $c = Capture::Tiny->new( ... ); } else { ## fallback if not have Capture::Tiny }

UPDATE 2: Based on the nodes below, my new way of doing this:

use strict; use warnings; # Instead of: # # use Module::Name 1.00 qw(:subs); # # do this: my $HAVE_Module_Name; BEGIN { $HAVE_Module_Name = eval { require Module::Name; Module::Name->VERSION( 1.00 ); Module::Name->import( qw ( :subs ) ); 1; }; } if ($HAVE_Module_Name) { print "Module::Name = $Module::Name::VERSION\n"; } else { print "Module::Name = [NOT INSTALLED]\n"; }