in reply to %{^CAPTURE}, %{^CAPTURE_ALL} and %- don't produce expected output
%{^CAPTURE_ALL} is documented to be an alias to %-, but it's clearly not. I think this qualifies as a bug. <update2> Yep: #131867 </update2> <update3> Plus #134193 </update3>
use warnings; use strict; use Data::Dump; my $s = "a aa aaa aaaa"; $s =~ /(?<a>a+) (?<a>a+) (?:(?<a>a+)bbb)?/; dd \%+; dd \%{^CAPTURE}; dd \%-; dd \%{^CAPTURE_ALL}; tie my %hash, "Tie::Hash::NamedCapture", all => 1; dd \%hash __END__ { # tied Tie::Hash::NamedCapture a => "a", } { # tied Tie::Hash::NamedCapture a => "a", } { # tied Tie::Hash::NamedCapture a => ["a", "aa", undef], } { # tied Tie::Hash::NamedCapture a => "a", } { # tied Tie::Hash::NamedCapture a => ["a", "aa", undef], }
Note, from perlre: "When different groups within the same pattern have the same name, any reference to that name assumes the leftmost defined group. ... Named captures are implemented as being aliases to numbered groups holding the captures ..." and I personally wouldn't use two named capture groups with the same name.
Update: The source is confusing me even more...
case '\003': /* $^CHILD_ERROR_NATIVE */ if (memEQs(name, len, "\003HILD_ERROR_NATIVE")) goto magicalize; /* @{^CAPTURE} %{^CAPTURE} */ if (memEQs(name, len, "\003APTURE")) { AV* const av = GvAVn(gv); const Size_t n = *name; sv_magic(MUTABLE_SV(av), (SV*)n, PERL_MAGIC_regdat +a, NULL, 0); SvREADONLY_on(av); if (sv_type == SVt_PVHV || sv_type == SVt_PVGV) require_tie_mod_s(gv, '-', "Tie::Hash::NamedCa +pture",0); } else /* %{^CAPTURE_ALL} */ if (memEQs(name, len, "\003APTURE_ALL")) { if (sv_type == SVt_PVHV || sv_type == SVt_PVGV) require_tie_mod_s(gv, '+', "Tie::Hash::NamedCa +pture",0); } break;
And it appears %{^CAPTURE_ALL} is not tested in the test suite, possibly explaining the issue...
|
|---|