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

Hi Monks, I am wriiting a script which will install some perl modules.Now my problem is that i am executing my script from some other directory for e.g my script is in /root/shashi/msa-prereq . Now my Makeinstall.PL file is in /root/shashi/msa-prereq/Tie-File-0.96 and thats why its giving an error. In case i am executing a command perl /root/shashi/msa-prereq/Tie-File-0.96/Makefile.PL Now this Makefile.PL is reading some other files which are in /root/shashi/msa-prereq/Tie-File-0.96 . Is there some option in perl through which I can execute Makefile.PL from some other directory

Replies are listed 'Best First'.
Re: execution of a perl script
by Corion (Patriarch) on Nov 10, 2005 at 09:31 UTC

    Is there a reason why you are not using CPAN.pm to install your modules?

    If you still need to do the installation locally, the following sequence will install the modules as if you typed the commands yourself:

    use Cwd; my $package = 'Tie-File-0.96'; sub run { my (@command) = @_; print "Running @command"; system(@command) == 0 or die "Couldn't run : $!"; }; my $old_dir = getcwd; run("tar", "xvzf", "$module.tar.gz" ); chdir $module or die "Couldn't chdir into '$module': $!"; run($^X,"-w","Makefile.PL"); run("make"); run("make","test"); run("make","install"); chdir $old_dir or die "Couldn't chdir into '$old_dir': $!";

    Update: Added restoral of the old directory

      Just to elaborate on the above suggestion, using CPAN.pm would make this trivial. Here's an example:
      use CPAN; use CPAN::Shell; for(qw/Tie::File Foo Bar/) { CPAN::Shell->install( $_ ); }
Re: execution of a perl script
by mikeock (Hermit) on Nov 10, 2005 at 15:49 UTC

    When you code the script, you can have it change to the directory where the makefile.pl is located for all modules to be installed. Something like the following:

    chdir "/root/shashi/msa-prereq/Tie-File-0.96/" or die "cannot chdir to + /root/shashi/msa-prereq/Tie-File-0.96/: $!"; system "Makefile.pl"; #other code #other code chdir ""/root/shashi/msa-prereq" or die "Cannot chdir to "/root/shashi +/msa-prereq: $!";

    Repeat the same code for all modules that need installed.

    Edit:Updated to change back to /root/shashi/msa-prereq befor changing to the next module folder