【问题标题】:perl passing parameters on windowsperl在windows上传递参数
【发布时间】:2017-09-02 16:02:22
【问题描述】:

我有以下代码:

$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"

但我没有得到任何结果。有人可以帮忙吗?

【问题讨论】:

    标签: windows perl parameters quotes


    【解决方案1】:

    通配符扩展是由 shell 完成的,但不是当参数被引号括起来时,在 windows 上移植 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 $@ if $@;
      rename ( $was, $_ ) unless $was eq $_;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 2012-09-09
      • 2013-05-03
      • 1970-01-01
      相关资源
      最近更新 更多