in reply to Re: RFC: named pattern match tokens
in thread RFC: named pattern match tokens
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: RFC: named pattern match tokens
by Jenda (Abbot) on Oct 04, 2004 at 22:46 UTC | |
by diotalevi (Canon) on Oct 04, 2004 at 23:10 UTC | |
|
Re^3: RFC: named pattern match tokens
by diotalevi (Canon) on Oct 04, 2004 at 22:12 UTC |