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

This may be really dumb, but I can't find the answer anywhere. I have a perl script that I want to call within another perl script. I searched the docs and came up with the command DO as in: do "/path/to/script.pl"; Ok that works just fine, but what if I want to pass a value to the perl script? I can't get that part working, ie: do "/path/to/script.pl argument1"; Maybe I'm just braindead but I can't get that to work. I've tried adding extra quotes in there, escaping the space character, etc to no avail. What should I do?
  • Comment on calling a perl script from within another perl script

Replies are listed 'Best First'.
Re: calling a perl script from within another perl script
by davido (Cardinal) on Jul 16, 2004 at 16:19 UTC
    doFILE; executes the Perl script as though it were actually a part of your currently running script. You might be looking to execute it using system() or the backticks instead. Or even open a pipe to it. See system, perlop (the section about the backtick operators), open for more details.


    Dave

      I had tried using backticks before and couldn't get that working for some reason. I just tried using the system() call and that worked just fine. Thanks for your help. Matt
Re: calling a perl script from within another perl script
by stonyy1 (Initiate) on Jul 16, 2004 at 16:37 UTC
    I use open and IPC::open3 a lot.
    open(MYSCRIPT, "foo arg1 $otherArgs |") or die "$!";
    @output = <MYSCRIPT>;
    close(MYSCRIPT);

    Use open3 if you need STDERR and STDOUT both.
Re: calling a perl script from within another perl script
by Roy Johnson (Monsignor) on Jul 16, 2004 at 18:10 UTC
    Just load up @ARGV with whatever you want to be the arguments to your other script.

    We're not really tightening our belts, it just feels that way because we're getting fatter.