Hi,
I'm getting this error:
3|assignment|>>Matched repeated subrule: [value]<< |
| |(1 times) |
3|assignment|Trying action |
Can't use an undefined value as an ARRAY reference at (eval 12) line 299, <DATA> line
4.
when trying to run this simple script:
#!/usr/bin/perl -w
use strict;
use vars qw($parser $text %hol);
use Data::Dumper;
use Parse::RecDescent;
$RD_HINT = 1;
$RD_TRACE = 1;
$parser = Parse::RecDescent->new(q(
mmpfile: chunk(s) /^\Z/
chunk: assignment | <error>
assignment: keyword <skip: '[ \t]*'> value(s) {
# add 1 or more values to the hash of lists
push @{$::hol{uc $item{keyword}}}, @{$item{value}};
}
keyword: /key\d+/
value: /val\d+/
)) or die 'Bad grammar';
$text .= $_ while (<DATA>);
defined $parser->mmpfile($text) or die 'bad text';
print Data::Dumper->Dump([\%hol], ['hash of lists']);
__DATA__
key1 val1
key2 val2 val3
on my OpenBSD-current PC with perl 5.8.3.
After reading the article about autovivification
http://tlc.perlarchive.com/articles/perl/ug0002.shtml
I've even tried this code to create a [] if needed:
assignment: keyword <skip: '[ \t]*'> value(s) {
# add 1 or more values to the hash of lists
push @{$::hol{uc $item{keyword}} ||= []}, @{$item{value}};
}
But the error stayed same. So I've decided that
it's not the first push() argument, but the second.
And the following code seems to work now:
assignment: keyword <skip: '[ \t]*'> value(s) {
push @{$::hol{uc $item{keyword}}},
ref $item{value} ? @{$item{value}} : $item{value};
}
However I don't see similar code in the demo/demo_*.pl
examples of R::PD... Also, I don't get the error on my
RedHat 9 PC at work with perl 5.8.0, but still get it
when using 5.8.2 on the same PC. That's confusing...
Regards
Alex