perl在Windows上传递参数

时间:2017-04-07 10:01:26

标签: windows perl parameters quotes

我有以下代码:

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

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

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

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

我得到了正确的结果。我尝试在Windows机器上执行相同的操作,安装了草莓perl,如

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

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

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

但我没有结果。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

Wilcard扩展是由shell完成的,但是当参数括在引号之间时,在窗口到端口perl脚本时有一个模块Win32 :: AutoGlob see also this SO question

快速修复:用(glob“@ARGV”)替换(@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 $@ if $@;
  rename ( $was, $_ ) unless $was eq $_;
}