in reply to Regexp::NamedCaptures, at last
Perhaps you should put in your docs that use re 'eval'; is required to get this to work - it complained when I tried without that. ;-)
Also, I tried the following:
just to try it out. I expected @x to contain 'baz'. Or to contain 'bbbbbbbb', 'baz'. I wasn't sure which. I got just 'bbbbbbbb'. Looking at the first line, $q, I see that convert managed to stop after the (?<$foo>\w+) portion - everything after that close-parenthesis was dropped.use Regexp::NamedCaptures; use re 'eval'; my $s = 'blah bbbbbbbb baz'; my $foo; my $q = Regexp::NamedCaptures::convert('blah (?<$foo>\w+) (\w+)(?:\s+( +\w+))'); print $q,"\n"; my @x = $s =~ qr/$q/; print "foo = $foo\n\@x = ", join(', ',map { "[$_]" } @x), "\n";
Thought you might like to know ;-)
Using perl 5.8.6 on linux.
Update: Two fixes. First, my code. That final (?:\s+(\w+)) needs a ? afterwards (an optional capture). Second, the original module: we need to insert else { $out .= $expression } at line 105 - after the if ( '(?<' ... block. Note that without the first fix, the regular expression doesn't match, but $foo gets set anyway. We probably need a way to back out the changes if the expression fails.
I'll leave you with this harder bug. ;-) However, that does mean that this does not quite behave as advertised - $foo is getting set even if the match fails, thus the "if (/.../) { $foo = $1 }" example in your perldoc is not quite describing how it behaves.
|
|---|