if ($str =~ /^(?<country>\d+)-(?<area>\d+)-(?<phone>\d+)$/) {
%num = %+;
}
Starting from 5.10 we can name the capturing parenthesis and the
strings they match will be in the %+ hash using the names of
the parenthesis as the keys.
Not only that but we can use these names also instead of the \1, \2
matching buffers y writing \k as in the following example:
Using names will make it much clearer what each pair of parenthesis
are matching and will eliminate bugs created when we add or remove
a pair that changes the numbering.
For example in this regex:
/(.)(.)\2\1/
If I want to add a repetition to it I would start writing
/((.)(.)\2\1){2}/
but this is incorrect and gives a syntax error as now I need to change
the numbers of the buffers:
/((.)(.)\3\2){2}/
Using named buffers even if they are just single letter will solve this problem: