问题
How to run a perl script from another passing parameters?
I'm trying to use a solution found in a internet post that i can't find anymore.
It was something like:
do 'script.cgi param1 param2';
And in the other script I'm using simply the shift to get those parameters:
#Parameters
my $param1= shift;
my $param2= shift;
I saw people using system with args, but is it better for real?
If not, how can I fix the solution with 'do EXPR'?
Thanks in advance.
回答1:
Oh well, I solved doing:
{local @ARGV = (@my_args); do $script;}
It works. If anybody has any better suggestions feel free to tell them to me.
Meantime i'm using this solution.
回答2:
Actually, there are two better ways I can think of:
system($script, @my_args);
and
my $cmd = $script . ' ' . join(' ', @my_args);
my $return = `$cmd`;
Both solutions pass the arguments in @my_args. The system() call returns the exit code of the executed program, while the backticks solution (``) returns the output for later parsing.
来源:https://stackoverflow.com/questions/12297890/how-to-run-a-perl-script-from-another-passing-parameters