http://qs321.pair.com?node_id=151228

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

I totally know how to call a perl program from another perl program. I have currently been using back ticks, but is there a way to not only call another perl program but to pass it parameters as well?

peace

basicdez

Replies are listed 'Best First'.
Re: Passing parameters into a perl program.
by dws (Chancellor) on Mar 12, 2002 at 21:15 UTC
    is there a way to not only call another perl program but to pass it parameters as well?

    TIMTOWTDI

    $output = `foo.pl $arg1 $arg2`; system("foo.pl $arg1 $arg2"); system("foo.pl", $arg1, $arg2);
    The difference in behavior between the last to examples is subtle, but worthy of study. It is well-described in perlfunc.

      Thanks
Re: Passing parameters into a perl program.
by derby (Abbot) on Mar 12, 2002 at 21:16 UTC
    basicdez,

    sure.

    • Pass 'em on the command line then read them out of @ARGV
    • skip backticks and system, use fork /exec, and pipe and send them from the parent to the child via STDIN
    • slightly more complicated: IPC

    -derby

Re: Passing parameters into a perl program.
by webadept (Pilgrim) on Mar 12, 2002 at 21:58 UTC
    Answer to your problem is above. If you are sending multiple parameters to an outside perl program, you may consider looking into building modules / classes or simply making an included function library. This way its easy to send and receive information and much more friendly on those that will see your code in the future.

    Of course there are plenty of valid reasons to do exactly what you are asking, so this is just a hint without cause :-)

    Glenn H.