How can I extract the matches from the Perl match operator into variables?

前端 未结 6 1047
无人及你
无人及你 2020-12-29 08:09

If I have a match operator, how do I save the parts of the strings captured in the parentheses in variables instead of using $1, $2, and so on?

6条回答
  •  情深已故
    2020-12-29 08:25

    Use the bracketing construct (...) to create a capture buffer. Then use the special variables $1, $2, etc to access the captured string.

    if ( m/(interesting)/ ) {
        my $captured = $1;
    }
    

提交回复
热议问题