%{^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...


In reply to Re: %{^CAPTURE}, %{^CAPTURE_ALL} and %- don't produce expected output (updated x3!) by haukex
in thread %{^CAPTURE}, %{^CAPTURE_ALL} and %- don't produce expected output by vr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.