[英]What's the difference between “$^N” and “$+”?
有人能告诉我一个例子,它展示了这两个变量的不同行为($ ^ N和$ +)?
From perldoc perlvar : 来自perldoc perlvar :
$+
: The text matched by the last bracket of the last successful search pattern.$+
:与上一个成功搜索模式的最后一个括号匹配的文本。
versus 与
$^N
: The text matched by the used group most-recently closed (ie the group with the rightmost closing parenthesis) of the last successful search pattern.$^N
:最近成功搜索模式最近关闭的使用组(即具有最右边右括号的组)匹配的文本。
This should illustrate the difference: 这应该说明不同之处:
#!/usr/bin/perl
use strict; use warnings;
my $s = '12345';
if ( $s =~ /(1([0-9]))/ ) {
print "$_\n" for $+, $^N;
}
Output: 输出:
2 12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.