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

前端 未结 6 1031
无人及你
无人及你 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:27

    You can use named capture buffers:

    if (/ (? .+? ) \s* : \s* (? .+ ) /x) { 
        $hash{$+{key}} = $+{value};
    }
    

提交回复
热议问题