TIE::HASH::NAMEDCAPTURE(3perl)

๐Ÿ’– NAME ๐Ÿ’–

Tie::Hash::NamedCapture โ€” named regexp capture buffers, bestie ๐ŸŽ€


โœจ SYNOPSIS โœจ

tie my %hash, "Tie::Hash::NamedCapture";
# %hash now behaves like %+

tie my %hash, "Tie::Hash::NamedCapture", all => 1;
# %hash now access buffers from regexp in $qr like %-

Periodt. That's literally the whole vibe. ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so listen. This module is what's behind the curtain for the special hashes %+ and %-. That's its whole job, no cap. But โ€” and this is the fun part โ€” you're not locked into that, you can tie other variables with it if you want to, your choice, main character energy. ๐Ÿ’œ

Now here's the tea on the all parameter:

  • When the all parameter is provided, the tied hash elements are gonna be array refs, each one listing the contents of every capture buffer whose name matches the associated hash key. ๐Ÿ˜ฎ If none of those buffers were actually involved in the match, then that array ref will hold as many undef values as there are capture buffers with that name. Basically: the tied hash is giving %-. fr fr.
  • When all is omitted or false, the tied hash elements are just the contents of the leftmost defined buffer with the name of the associated hash key. In other words, the tied hash is giving %+. ๐Ÿ’–

And the key situation, because keys are a whole thing here:

  • The keys of %--like hashes correspond to all the buffer names found in the regular expression. All of them.
  • The keys of %+-like hashes list only the names of the buffers that actually captured โ€” which means only the ones that got themselves associated with defined values. slay. โœจ
๐Ÿซถ heads up: this implementation has been moved into the core executable, but you can still load this module for backward compatibility. So like, it still works, it's fine, don't panic.

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

  • perlreapi
  • re
  • "Pragmatic Modules" in perlmodlib
  • "%+" in perlvar
  • "%-" in perlvar

perl v5.44.0 ยท 2026-10-17 โ€” and that's the whole page, bestie. go tie some hashes, you ate that ๐Ÿ’…๐ŸŒธ๐Ÿ’–

๐Ÿ“ฆ where this page comes from
  • arch rolling: perl 5.44.0-1 ยท Artistic-1.0-Perl AND GPL-1.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms