Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

I need to install PERL MODULE first and then use it in the same SCRIPT. Is it possible

by rahulruns (Sexton)
on Nov 29, 2012 at 08:09 UTC ( #1006188=perlquestion: print w/ replies, xml ) Need Help??
rahulruns has asked for the wisdom of the Perl Monks concerning the following question:

The code I am using is

if (eval {require Term::Menus;1;} ne 1) { print "INSTALLING PERL Term::Menus MODULE\n\n"; system("/opt/hp/hadooptools/validation/smoke/cpan.sh Term::Men +us"); } use Term::Menus; Error Can't locate Term/Menus.pm in @INC (@INC contains: /usr/local/lib64/pe +rl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/pe +rl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at check.pl line + 14. BEGIN failed--compilation aborted at check.pl line 14.

Comment on I need to install PERL MODULE first and then use it in the same SCRIPT. Is it possible
Download Code
Re: I need to install PERL MODULE first and then use it in the same SCRIPT. Is it possible
by tobyink (Abbot) on Nov 29, 2012 at 08:32 UTC

    Try:

    BEGIN { # This unless block just seems a little clearer than the # way you were doing it. # unless (eval { require Term::Menus }) { print "INSTALLING PERL Term::Menus MODULE\n\n"; system("/opt/hp/hadooptools/validation/smoke/cpan.sh Term::Menus +"); } } use Term::Menus;

    Explanation: use happens at compile-time, before your check/install code runs. Wrapping it in a BEGIN block "lifts" that code to compile-time.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Thank you pointing in right direction a great help

Re: I need to install PERL MODULE first and then use it in the same SCRIPT. Is it possible
by CountZero (Bishop) on Nov 30, 2012 at 07:18 UTC
    CPAN::AutoINC

    From its docs:

    When CPAN::AutoINC is loaded, it will add itself to @INC and catch any requests for missing resources. If a Perl module is requested CPAN will be queried and, assuming that the module exists on CPAN, CPAN::Shell will be invoked to install it. Execution of the script continues after the requisite module has been installed.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2014-08-22 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (163 votes), past polls