in reply to Re^2: Check if module is installed
in thread Check if module is installed

You want string eval:
eval "use Some::Module 94.5"; if($@) { print "Oh noes, it's not installed!\n"; } else { ... }

Replies are listed 'Best First'.
Re^4: Check if module is installed
by JavaFan (Canon) on Nov 16, 2009 at 11:46 UTC
    Checking $@ is not an appropriate way to check if an eval failed. An eval can fail, but in the clean up (DESTROY for instance), something can unset $@.

    The only way to make sure an eval succeeded is to check its return value:

    eval "use Some::Module 94.5; 1" or do { printf "Loading Some::Module failed: %s", $@ // "Unknown error"; ... };
      Can you give an example that would make my code Do The Wrong Thing? Cos I can't think of any way of doing that.