in reply to Parse::RecDescent startup/input error

I don't know wether it's a typo or not but you are missing a ; on the first commented line. You may also want to look at using $return to get data out of the productions rather than modifying global vars. Something like this may work
file: hdr body ftr { $return = {hdr => $item{hdr}, body => $item{body}, }; } body: batch(s) hdr: /^HDR.*\\n/ ftr: /^FTR.*\\n/ batch: bathdr tran(s) batftr { $return = {bathdr => $item{bathdr}, tran => $item{"tran(s)"}, }; } bathdr: /^BHD.*\\n/ { $return = substr($item[1], 30, 3); } batftr : /^BFT.*\\n/ tran: TR1 TR2 { $return = {%{$item{TR1}}, %{$item{TR2}}, }; } TR1: /^TR1.*\\n/ { $return = { str4 => substr($item[1], 35, 8), str2 => substr($item[1], 122, 5), }; } TR2: /^TR2.*\\n/ { $return = {str3 => substr($item[1], 103,2)}; }
the return from the parser will be the datastructure you created and you can then print/manipulate it outside of the parser. Not tested at all.

Replies are listed 'Best First'.
Re^2: Parse::RecDescent startup/input error
by JESii (Novice) on Aug 06, 2004 at 17:46 UTC
    Thanks for your suggestion; I'll give it a try.

    In the meantime, I figured out how to solve the problem; I just don't understand why.
    The P::RD docs say:

    "...since each rule is implemented inside a special namespace belonging to its parser,
    it is necessary to explicitly quantify variables form the main package."


    Therefore, I changed all variables to refer to the Main package. I.e., $str1 becomes $Main::str1, and now it works. But why it spits out this particular error message is beyond me.

    Thanks...

    "The only things that are difficult are thoese that I know nothing about" -- Mark Twain