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
精彩评论