I keep getting the following error from P::RD:
Can't call method "file" on an undefined value at ../scan_test.plx line 46, <> line 1.
file is my startup rule. I test my input text and it is defined and contains the data I expect.
As long as I am just printing out the tokens that have been extracted, everything works OK. But as soon as I try to save some of the data for later use, the grammar breaks down. Here's the entire grammar (yes, P::RD is overkill, but I figured it would be quick and easy to get running):
my $grammar = q{
file: hdr body ftr
hdr: /^HDR.*\\n/ {
print "HDR: $item[1]";
}
body: batch(s)
ftr: /^FTR.*\\n/
batch: bathdr tran(s) batftr
bathdr: /^BHD.*\\n/ {
# $str1= substr($item[1],30,3)
1;
}
tran: TR1 TR2
batftr: /^BFT.*\\n/
TR1: /^TR1.*\\n/ {
# $str4= substr($item[1],35,8);
# $str2= substr($item[1],122,5);
1;
}
TR2: /^TR2.*\\n/ {
# $str3= substr($item[1],103,2);
# print "DATA: $str1, $str2, $str3, $str4\\n";
1;
}
};
If I run the script as is, it works. If I uncomment any one of the commented actions above, it fails with the 'undefined value' error.
Any help would be appreciated. So far, re-reading the perldoc and the P::RD FAQ haven't helped.
Thanks...
"The only things that are difficult are those that I know nothing about" -- Mark Twain
janitored by ybiC: Fix typo in nodetitle - s/Prarse/Parse/
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.