in reply to Strange behavior of @- and @+ in perl5.10 regexps
When running the following program with perl v5.8.8 or v5.10.1@LAST_MATCH_END @+ ... You can use $#+ to determine how many subgroups were in the last successful match. ... @LAST_MATCH_START @- ... One can use "$#-" to find the last matched subgroup in the last successful match. Contrast with $#+, the number of subgroups in the regular expression.
produces the same output:pl@nereida:~/Lperltesting$ cat abigail1.pl #!/usr/bin/perl local $" = ", "; "a" =~ /(a)|(b)/; print "\@- = (@-)\t length of \@- = ".((scalar @-)."\t last - index = +$#-\n"); print "\@+ = (@+)\t length of \@+ = ".((scalar @+)."\t last + index = +$#+\n")
and so the behavior of the perl 5.10 regexp engine is perfectly right. The last matched subgroup is subgroup 1 but there were 2 groups in the last successful match.pl@nereida:~/Lperltesting$ perl5.10.1 ./abigail1.pl @- = (0, 0) length of @- = 2 last - index = 1 @+ = (1, 1, ) length of @+ = 3 last + index = 2 pl@nereida:~/Lperltesting$ perl5.8.8 ./abigail1.pl @- = (0, 0) length of @- = 2 last - index = 1 @+ = (1, 1, ) length of @+ = 3 last + index = 2
|
|---|