我想知道是否有一个运营商名称%+
,所以代替以下代码:
/(?<CaptureName>\w+)/;
...
my $whatever=$+{CaptureName};
Run Code Online (Sandbox Code Playgroud)
我可以使用更具可读性的东西:
use English;
/(?<CaptureName>\w+)/;
...
my $whatever=$?????{CaptureName};
Run Code Online (Sandbox Code Playgroud)
使用英语模块,您可以将其称为%LAST_PAREN_MATCH
:
use English;
/(?<CaptureName>\w+)/;
...
my $whatever = $LAST_PAREN_MATCH{CaptureName};
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)%LAST_PAREN_MATCH %+ Similar to "@+", the "%+" hash allows access to the named capture buffers, should they exist, in the last successful match in the currently active dynamic scope.
你可以参考http://perldoc.perl.org/perlvar.html以后找到符号名称.
在您的情况下,sylbe称为LAST_PAREN_MATCH
%LAST_PAREN_MATCH
%+
Similar to @+ , the %+ hash allows access to the named capture buffers, should they exist, in the last successful match in the currently active dynamic scope.
Run Code Online (Sandbox Code Playgroud)
例如,$ + {foo}在以下之后相当于$ 1
我要做的唯一一点就是文档包括:
This variable was added in Perl v5.10.0.
Run Code Online (Sandbox Code Playgroud)
因此,如果您使用较旧的翻译,这可能会导致问题.
请注意,正如Keith在下面的评论中指出的那样,您也可以使用perldoc -v '$+'
.只有符号在您安装的Perl版本上可用时才有效.