jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I would like to write a program that checks for some modules that should be installed.
What is the best way to check, for example, if XML::Simple is installed ?

Thanks in advance
Luca

Replies are listed 'Best First'.
Re: check for modules
by marto (Cardinal) on Jan 23, 2006 at 13:09 UTC
Re: check for modules
by explorer (Chaplain) on Jan 23, 2006 at 13:02 UTC
Re: check for modules
by mirod (Canon) on Jan 23, 2006 at 13:42 UTC

    The traditionnal way is to wrap the require of the module in an eval:

    if( eval "require $module") { import $module; } else { # die or apply contingency procedure }
      I prefer just:
      eval "use $module; 1" or die "or apply contingency procedure";
      If $module comes from an untrusted source, be sure to validate it before using in eval.
Re: check for modules
by holli (Abbot) on Jan 23, 2006 at 14:11 UTC