Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Is there another way to get named captures

by Fletch (Bishop)
on Jan 09, 2022 at 04:46 UTC ( [id://11140297]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Is there another way to get named captures
in thread Is there another way to get named captures

Aaah I've apparently missed (as in misread) what they're looking for and why (thinking that they're objecting to the punctuation-ness). Once you mentioned that I was thinking maybe the tied version captured %+ at the point of tying but experimenting shows it's affected by the global state so no dice there.

I could maybe imagine roughing out some sort of "matching state" context object that captures (ha) all of this stuff and returns an independent instance but that's getting back along the lines of your sample in that you'd need to use something else rather than native m{} or what not.

use Hypothetical::MatchState qw( matchit ); my $match1 = matchit( $_ => $regex ); my $match2 = matchit( $other => $regex ); say $_->named( q{foo} ) for ( $match1, $match2 );

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

Replies are listed 'Best First'.
Re^4: Is there another way to get named captures
by AlexP (Pilgrim) on Jan 09, 2022 at 11:39 UTC
    Great idea for a small module!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found