[英]When I run a file which is begin with “#!/usr/bin/perl -w”, I get a error: “syntax error at line 153, near ”=~ ?“”
When I run a file which is begin with #!/usr/bin/perl -w
, I get a error: 当我运行以
#!/usr/bin/perl -w
开头的文件时,出现错误:
syntax error at line 153, near "=~ ?"
第153行的语法错误,靠近“=〜?”
I try to add "#!/bin/bash", this error is not append, but I get another 我尝试添加“#!/ bin / bash”,这个错误没有附加,但我得到另一个
error: "line 34: syntax error near unexpected token `('"
错误:“第34行:意外令牌附近的语法错误`('”
line 153 in my file: 我文件中的第153行:
($output_volume =~ ?^([\S]+).mnc?) && ($base_name = $1) ||
die "sharpen_volume failed: output volume does not appear to be"
." a minc volume.\n";
line34 in my file: use MNI::Startup qw(nocputimes); 我文件中的line34:使用MNI :: Startup qw(nocputimes);
$output_volume =~ ?^([\S]+).mnc?
This used to be valid perl and thus might appear in old code and instructional material. 这曾经是有效的perl,因此可能出现在旧代码和教学材料中。
In the past, the leading m in m?PATTERN?
在过去,m?PATTERN的领先者? was optional, but omitting it would produce a deprecation warning.
是可选的,但省略它会产生弃用警告。 As of v5.22.0, omitting it produces a syntax error.
从v5.22.0开始,省略它会产生语法错误。 If you encounter this construct in older code, you can just add m.
如果您在旧代码中遇到此构造,则可以添加m。
That is Perl code so the first error message is meaningful. 这是Perl代码,因此第一条错误消息是有意义的。
With delimiters other than //
in the match operator you must have the explicit m
for it, so 比其他的分隔符
//
在匹配运算符,你必须有明确的m
吧,这样
$output_volume =~ m?^([\S]+).mnc?
It is only with //
delimiters that the m
may be omitted. 只有
//
分隔符才能省略m
。
From Regex Quote-Like Operators (in perlop) 来自正则表达式报价操作员(在perlop中)
If
"/"
is the delimiter then the initialm
is optional.如果
"/"
是分隔符,则初始m
是可选的。
See perlretut for a tutorial introduction to regex and perlre for reference. 有关regex和perlre的教程介绍,请参阅perlretut以供参考。
Also note that the particular delimiters of ?
还要注意特定的分隔符
?
trigger specific regex behavior in a special case. 在特殊情况下触发特定的正则表达式行为。 This is discussed by the end of the documentation section in
perlop
linked above. 这将在
perlop
链接的perlop
文档部分的末尾讨论。
You already have two answers that explain the problem. 您已经有两个解释问题的答案。
? ... ?
is no longer valid syntax for a match operator. m? ... ?
m? ... ?
m? ... ?
instead. There are, however, a few other points it is probably worth making. 但是,还有一些其他观点可能值得制作。
#!/usr/bin/perl -w
to #!/bin/bash
. #!/usr/bin/perl -w
更改为#!/bin/bash
来调查此问题。 I'm not sure how you think this was going to help. m? ... ?
m? ... ?
m? ... ?
(or, formerly, ? ... ?
) syntax triggers an obscure and specialised behaviour. ? ... ?
)语法触发了一种模糊和专门的行为。 It seems to me that this behaviour isn't required in your case, so you can probably change it to the more usual / ... /
. / ... /
。 \\.
) so that it matches an actual dot (rather than any character). \\.
),以使其与实际点(而不是任何字符)匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.