1 package Tie::Hash::NamedCapture;
5 # The real meat implemented in XS in universal.c in the core, but this
6 # method was left behind because gv.c expects a Purl-Perl method in
7 # this package when it loads the tie magic for %+ and %-
9 my ($one, $all) = Tie::Hash::NamedCapture::flags();
13 my $flag = $arg{all} ? $all : $one;
18 tie %-, __PACKAGE__, all => 1;
26 Tie::Hash::NamedCapture - Named regexp capture buffers
30 tie my %hash, "Tie::Hash::NamedCapture";
31 # %hash now behaves like %+
33 tie my %hash, "Tie::Hash::NamedCapture", all => 1;
34 # %hash now access buffers from regexp in $qr like %-
38 This module is used to implement the special hashes C<%+> and C<%->, but it
39 can be used to tie other variables as you choose.
41 When the C<all> parameter is provided, then the tied hash elements will be
42 array refs listing the contents of each capture buffer whose name is the
43 same as the associated hash key. If none of these buffers were involved in
44 the match, the contents of that array ref will be as many C<undef> values
45 as there are capture buffers with that name. In other words, the tied hash
48 When the C<all> parameter is omitted or false, then the tied hash elements
49 will be the contents of the leftmost defined buffer with the name of the
50 associated hash key. In other words, the tied hash will behave as
53 The keys of C<%->-like hashes correspond to all buffer names found in the
54 regular expression; the keys of C<%+>-like hashes list only the names of
55 buffers that have captured (and that are thus associated to defined values).
59 L<perlreapi>, L<re>, L<perlmodlib/Pragmatic Modules>, L<perlvar/"%+">,