有人能告诉我一个例子,它展示了这两个变量的不同行为($ ^ N和$ +)?
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 (ie 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.