http://qs321.pair.com?node_id=659220

philcrow has asked for the wisdom of the Perl Monks concerning the following question:

I've started playing with the named capture and grammar features of 5.10. I like what I see, but I did find something that stumped me.

If I use a named capture I get what I expect:

#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $number_re = qr{ (?<int> \d+) }x; my $num = 15; if ( $num =~ /^$number_re$/ ) { warn "'$num' is valid\n"; warn Dumper( \%- ); } # produces: #'15' is valid #$VAR1 = { # 'int' => [ # '15' # ] # };
But, when I try to DEFINE a grammar, the named capture only stores undef:
#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $number_re = qr{ (?(DEFINE) (?<int> \d+ ) ) (?&int) }x; my $num = 15; if ( $num =~ /^$number_re$/ ) { warn "'$num' is valid\n"; warn Dumper( \%- ); } # produces: #'15' is valid #$VAR1 = { # 'int' => [ # undef # ] # };
Am I missing something?

(Perhaps my excitement at the new grammar features has raised my expectations too high. I was starting to hope for a parse tree.)

Phil

The Gantry Web Framework Book is now available.