As it shows in perlvar if you use English there's also %{^CAPTURE} and %{^CAPTURE_ALL} respectively:

## Being lazy and using the Mojo "ojo" oneliner for it's dumper r() $ perl -Mojo -MEnglish -E '$_ = q{foo = bar};m{(?<name>\w+) \s* = \s* +(?<value>.*) $}x; say r(\%{^CAPTURE})' { "name" => "foo", "value" => "bar" }

That being said (IMHO) eliminating every single magic variable isn't really getting you that much of a gain for the extra typing you're setting yourself up to do (${^CAPTURE}{name} vs $+{name}). Some things are just idiomatic perl and going out of your way to make things more cumbersome to type for (again, IMHO) minor "readability" improvements isn't really helpful.

Edit: Or if you read perlvar more carefully it mentions Tie::Hash::NamedCapture which lets you create a named alias which was exactly what you'd asked for. Derp. Since this lets you give the tied hash a semantically meaningful name yourself I'd say that's marginally more valid, but still a bit of . . . not overkill, but maybe more effort than it's worth for a (small) benefit over $+{foo}.

$ perl -Mojo -MTie::Hash::NamedCapture -E '$_ = q{foo = bar};m{(?<name +>\w+) \s* = \s* (?<value>.*) $}x; tie my %h, q{Tie::Hash::NamedCaptur +e}; say r(\%h)' { "name" => "foo", "value" => "bar" }

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re: Is there another way to get named captures by Fletch
in thread Is there another way to get named captures by AlexP

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.