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

Ok!
No, It's not installed, the purpose was to create some "try/catch" code to catch the error if the module isn't installed, since the code is to be distributed to several machines.

Replies are listed 'Best First'.
Re^3: Check if module is installed
by DrHyde (Prior) on Nov 16, 2009 at 11:32 UTC
    You want string eval:
    eval "use Some::Module 94.5"; if($@) { print "Oh noes, it's not installed!\n"; } else { ... }
      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.