perl - 当我运行以 "#!/usr/bin/perl -w"开头的文件时,出现错误 : "syntax error at line 153, near "=~ ?""

标签 perl

当我运行以 #!/usr/bin/perl -w 开头的文件时,我收到一个错误:

syntax error at line 153, near "=~ ?"



我尝试添加“#!/bin/bash”,这个错误不是附加的,但我得到了另一个

error: "line 34: syntax error near unexpected token `('"



我的文件中的第 153 行:
($output_volume =~ ?^([\S]+).mnc?) && ($base_name = $1) ||
  die "sharpen_volume failed: output volume does not appear to be"
  ." a minc volume.\n";

我的文件中的第 34 行:
使用 MNI::Startup qw(nocputimes);

最佳答案

$output_volume =~ ?^([\S]+).mnc?

这曾经是有效的 perl,因此可能会出现在旧代码和教学 Material 中。

来自 perlop :

In the past, the leading m in m?PATTERN? was optional, but omitting it would produce a deprecation warning. As of v5.22.0, omitting it produces a syntax error. If you encounter this construct in older code, you can just add m.

关于perl - 当我运行以 "#!/usr/bin/perl -w"开头的文件时,出现错误 : "syntax error at line 153, near "=~ ?"",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57604807/

相关文章:

perl - 使用 Perl 删除 XML 节点 - 这个或那个

python - Perl 和 Python 在预声明函数方面的区别

perl - 如何在 Perl 中评估字符串中的链式表达式?

perl - perl v24 中的 ${^MATCH} 和/p 修饰符

perl - 仅使用低优先级短路运算符警告无效上下文

regex - 如何停止搜索单词(regex、grep)?

perl - 为什么 Perl open() 文档使用两种不同的 FILEHANDLE 样式?

regex - Perl 正则表达式 获取电子邮件地址

perl - 如何找到给定目录中最大的 10 个文件?

perl - 在 Perl 中检测编译阶段