Here's something I don't understand and would appreciate enlightenment about. The (?=(pattern)) regex expression is pretty standard for extracting overlapping sub-strings, character pairs in the example below. However, when combined with embedded eval-ed code, the code is, for some reason unknown to me, evaluated twice. This is the case whether the eval-ed code block is inside or outside of the look-ahead group. Note that the output list of extracted matches is as expected.
The example code functions identically in ActiveState 5.8.9 and Strawberries 5.10.1.5 and 5.12.3.0, and also behaves identically if $1 is used instead of $^N.
Many thanks in advance for any insight on this question.
>perl -wMstrict -le "my $s = 'abcd'; ;; my @pairs1 = $s =~ m{ (?= (..)) (?{ printf qq{'$^N' } }) }xmsg; print ''; printf qq{:$_: } for @pairs1; print ''; ;; my @pairs2 = $s =~ m{ (?= (..) (?{ printf qq{'$^N' } })) }xmsg; print ''; printf qq{:$_: } for @pairs2; print ''; " 'ab' 'ab' 'bc' 'bc' 'cd' 'cd' :ab: :bc: :cd: 'ab' 'ab' 'bc' 'bc' 'cd' 'cd' :ab: :bc: :cd:
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |