2

I'm using the following code to install a Perl module but it's prompting some questions during the installation:

BEGIN{
    unless( eval { require Archive::Extract } ){
        require CPAN;
        CPAN::Shell->force("install","Archive::Extract");
    }
}
use Archive::Extract;

The matter is some old Perl installations (like 5.8) don't contain this useful module and I'm not sure what to use instead of it ))

I have tried different ways to work around this problem, like using PERL_MM_USE_DEFAULT=1 in the code but still with no luck. This forum contains some answers like to define a hash with the default settings but these ways are too complicated for a newbee.

Is there any simpler way to install a module with no prompt? Thank you very much.

Update: I am using different Linux derivatives like Ubuntu 10.04, CentOS 6 and so on. I am installing a piece of software with the help of this script (for my personal use only).

Andrew
  • 241
  • 3
  • 12
  • What versions of perl or CPAN.pm are you having problems with? What questions are being asked? – ysth Feb 26 '12 at 09:35
  • 5
    Don't. If you are writing software that has dependancies, then specify them in your Makefile. Dependancies are something for the installer to take care of. The program should fall over with a "cannot find module" error, not try to install something that the user may not have (system) permissions to install. – Quentin Feb 26 '12 at 09:42
  • Yes, I understand that I should not. But the script is intended for my personal use. I am trying to install some software with the help of this script. I will try reading about the Makefiles. – Andrew Feb 26 '12 at 09:53
  • 2
    Further information to back up Quentin's advice: http://stackoverflow.com/questions/9340046/perl-script-to-check-if-perl-modules-are-installed#comment11789589_9340046 http://stackoverflow.com/questions/9201401/force-module-install-with-cpan#comment11591892_9201401 http://stackoverflow.com/questions/7664829/can-a-perl-script-install-its-own-cpan-dependencies – daxim Feb 26 '12 at 11:01
  • Thanks, I will choose the way of checking modules and warn if a needed module is not installed. – Andrew Feb 26 '12 at 11:10

0 Answers0