What is the meaning of the “keys %+” in perl?

前端 未结 3 1416
北荒
北荒 2021-01-21 06:10

Short question: What\'s mean the

keys %+

in perl?

I saw it in some source code.

相关标签:
3条回答
  • 2021-01-21 06:19

    The hash %+ has all the matches from named capture groups in regexes in the current scope. It's explained in perlvar under %LAST_PAREN_MATCH and was added in 5.10.

    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. [..]

    The keys function lists all the keys in the hash.

    0 讨论(0)
  • 2021-01-21 06:25

    Whenever you see a groovy-looking variable, look it up in perldoc perlvar.

    In this case, %+ is the hash that stores the values corresponding to the named captures of the last regex:

    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. For example, $+{foo} is equivalent to $1 after the following match:

    'foo' =~ /(?<foo>foo)/;
    

    See perldoc perlretut for more details.

    0 讨论(0)
  • 2021-01-21 06:25

    These docs are what you want:

    perldoc -f keys

    perldoc -v %+

    0 讨论(0)
提交回复
热议问题