【发布时间】:2015-03-15 15:25:45
【问题描述】:
当我尝试在我的 perl 脚本中执行 perl 脚本时遇到了一个问题。这是我正在进行的一个更大项目的一小部分。
下面是我的 perl 脚本代码:
use strict;
use warnings;
use FindBin qw($Bin);
#There are more options, but I just have one here for short example
print "Please enter template file name: "
my $template = <>;
chomp($template);
#Call another perl script which take in arguments
system($^X, "$Bin/GetResults.pl", "-templatefile $template");
“GetResults.pl”有多个参数,我这里只提供一个。基本上,如果我要单独使用 GetResults.pl 脚本,我会在命令行中输入:
perl GetResults.pl -templatefile template.xml
我在上面的系统函数调用中遇到了两个问题。首先,当我运行我的 perl 脚本时,它似乎删除了我的参数前面的破折号,导致 GetResults.pl 中出现无效参数错误。
然后我尝试了这个
system($^X, "$Bin/GetResults.pl", "/\-/templatefile $template");
它似乎没问题,因为它没有抱怨早期的问题,但现在它说它找不到 template.xml,尽管我将该文件与我的 perl 脚本以及 GetResults.pl 脚本放在同一位置。如果我只是单独运行 GetResults.pl 脚本,它可以正常工作。
我想知道当我使用变量 $template 和位于我的 PC 上的真实文件名(我使用的是 Window 7)时,字符串比较是否存在问题。
我是 Perl 新手,希望有人能提供帮助。提前谢谢你。
【问题讨论】: