2017-04-07 50 views
0

我有以下代码:Perl的传递参数在Windows

$op = shift or die "Usage: rename expr [files]\n"; 
chomp(@ARGV = <STDIN>) unless @ARGV; 
print "$op"; 

for (@ARGV) 
{ 
    print "$_"; 
    $was = $_; 
    eval $op; 
    die [email protected] if [email protected]; 
    rename ($was, $_) unless $was eq $_; 
} 

它产生的Linux机器上,即在预期的结果,当我运行

perl massrenamer.pl 's/\.txt/\.txtla/' *.txt 

我得到正确的结果。我尝试执行Windows机器上同样的事情,并安装像

perl massrenamer.pl 's/\.txt/\.txtla/' *.txt 

perl massrenamer.pl "s/\.txt/\.txtla/" *.txt 

perl massrenamer.pl 's/\.txt/\.txtla/' "*.txt" 

草莓perl的,但我没有得到任何结果。有人可以帮忙吗?

回答

2

Wilcard扩展外壳环境进行的,而不是当参数被封闭引号之间,对窗口端口Perl脚本有一个模块的Win32 :: AutoGlob see also this SO question

速战速决:更换(@ARGV) (glob“@ARGV”)

$op = shift or die "Usage: rename expr [files]\n"; 
chomp(@ARGV = <STDIN>) unless @ARGV; 
print "$op"; 

for (glob "@ARGV") 
{ 
    print "$_"; 
    $was = $_; 
    eval $op; 
    die [email protected] if [email protected]; 
    rename ($was, $_) unless $was eq $_; 
}