How to run a perl script from another passing parameters?

眉间皱痕 提交于 2019-12-26 04:22:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!