Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Checking and installing a perl module

by Anonymous Monk
on Jun 11, 2009 at 11:56 UTC ( [id://770616]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks, I want to write a script which will check whether a module is installed in a linux machine and if it is not installed the script should install it.....How can I write that?? Thanks in advance

Replies are listed 'Best First'.
Re: Checking and installing a perl module
by afoken (Chancellor) on Jun 11, 2009 at 12:00 UTC

    It already exists and is named cpan.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      BEGIN { eval('use abc::fdj'); if($@) { die "You need to install ModuleName...\n" if $@; #`perl -MCPAN -e shell | install abc::def`; # `install abc::def`; } else { print "The module is installed\n"; } }
      This will check whether a module is installed....But how to install it from the script if it is not installed??
        my $module = 'My::Module'; system(cpan => $module) and die("system cpan failed: $!/$?\n");
Re: Checking and installing a perl module
by linuxer (Curate) on Jun 11, 2009 at 12:05 UTC

    You could eval a use of the desired module and check $@ afterwards.

    How do you want to install the module? With CPAN? With system's package system?

    I'd prefer that the script aborts with an information for the user, if the module is not installed. Let the user handle the installation of modules. Best of all, this already happens when using a not installed module.

    Don't mess up the system installation ... How do you know the user's preferences where to install which modules?

      No I will check for only one Module....I will run my script in different machines....If the module is not installed, then the script should install it.....
        Are there underlying (and self-evidently, unstated) reason(s) why you don't use NFS mounted extra libraries ??

        In that way, you remove the need to maintain libraries across a load of disparate machines (and installations) with all the attendant problems - at least one of which, you've now encountered.

        A user level that continues to overstate my experience :-))
Re: Checking and installing a perl module
by mhearse (Chaplain) on Jun 11, 2009 at 23:34 UTC
    And another way. Where mod_list contains a list of modules to check for.
    #!/bin/bash export FTP_PASSIVE=1 cat mod_list | while read module do perl -M$module -e exit 2> /dev/null || { echo "Missing $module" perl -MCPAN -e "install $module" } done

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://770616]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found