in reply to Check if module is installed

perldoc -f require : no option for checking the version on a module like with use.

I hate to ask a stupid question, but when troubleshooting I always start at the "is it plugged in" basics: Is Mail::Sendmail installed?

Replies are listed 'Best First'.
Re^2: Check if module is installed
by DreamT (Pilgrim) on Nov 16, 2009 at 11:08 UTC
    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.
      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"; ... };