in reply to Gracefully choosing which module to use

I've used:

if (eval "use Module::Foo") { # I've got foo! } else { die $@ if $@; }

If evaling a string makes you squirmy, this should work the same:

if (eval { require Module::Foo }) { Module::Foo->import() if Module::Foo->can('import'); # I've got foo! } else { die $@ if $@; }

Note that this will not work:

if (eval { use Module::Foo }) { # I've got foo! } else { die $@ if $@; }

That's because use is a compile-time statement which can't be trapped by an eval. It'll blow up at compile time if Module::Foo can't be loaded.

-sam