开发者

What's the difference between "$^N" and "$+"?

Can someone show me an example which demonstrates the different beha开发者_JS百科vior of these two variables ( $^N and $+ )?


From 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 (i.e. the group with the rightmost closing parenthesis) of the last successful search pattern.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜