You might also like to look at extending the regexp syntax
I thought about this, but didn't have any experience doing so. I just went with what I know, but I may take a look at your code, and see how it works.
It copies the contents of the last closed capture into the scalar variable named 'name'
I'm not sure I like this part. The idea of extending regular expression syntax is nice, but storing the matches in arbitrary scalars seems a bit sloppy. Maybe this can be reworked to store the results in a hash.
Something along the lines of:
use re 'eval'; use strict; my $re = convert('(foo)\C{ foo }'); my %hash; "foo bar" =~ $re; print $hash{foo}, "\n"; sub convert { my $re = shift; $re =~ s( \\ ( \\ | C\{ (?>\s*) ((?>\w+)) (?>\s*) \} ) ) { defined $2 ? "(?{\$hash{$2}=\$^N})" : "\\" }xeg; $re; }
This is only marginally better, though, because instead of clobbering any arbitrary number of scalar variables, it clobbers one hash. Maybe there's a cleaner way to handle this.
In reply to Re^2: RFC: named pattern match tokens
by revdiablo
in thread RFC: named pattern match tokens
by revdiablo
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |