demerphq has asked for the wisdom of the Perl Monks concerning the following question:
The data (a file) that I need to parse looks like this:
and the grammer I am using looks like this:HDRCOMPNAME BIG000OLD111IDENTIFIER1020301WITH1010LOTS1010OF1010CRAP ADD,1234567890,,COMPNAME ADDRANGE,2468,4680,COMPNAME DELETE,987654321,,COMPNAME DELETERANGE,13579,13599,COMPNAME TLR000004
If its not obvious I have used the postfix _t for tokens.my $Grammar=<<'END_GRAMMAR'; startrule : file file : header record(s?) trailer_t { $return={ header=>$item[1], records=>$item[2], count=>$item[3] } } header : header_t data_t { $return={ company=>$item[1], code=>$item[2] } } record : valid_rec | <error> valid_rec : type_t ',' number_t ',' number_t(?) ',' name_t { $return=[ $item[1], $item[3], @{$item[5]} ? $item[5] : undef, $item[7] ] } header_t : /HDR\w+/ { $return=substr($item[1],3) } trailer_t : /TLR\d+/ { $return=substr($item[1],3) } data_t : /\w+/ type_t : /ADD(?:RANGE)?|DELETE(?:RANGE)/ number_t : /\d+/ name_t : /\w+/ END_GRAMMAR
Any wisdom regarding this would be really appreciated. Especially if there is some way to modify the grammer to enhance speed. These files can contain thousands+ records and the speed hit is seriously making me think of hand rolling this (which I really really dont want to do).
Thanks in advance,
Yves / DeMerphq
--
This space for rent.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: advice with Parse::RecDescent
by merlyn (Sage) on Dec 10, 2001 at 20:13 UTC | |
by demerphq (Chancellor) on Dec 10, 2001 at 20:24 UTC | |
by demerphq (Chancellor) on Dec 10, 2001 at 21:36 UTC | |
|
Re: advice with Parse::RecDescent
by TheDamian (Vicar) on Dec 11, 2001 at 01:56 UTC | |
|
Re: advice with Parse::RecDescent
by miyagawa (Chaplain) on Dec 10, 2001 at 18:20 UTC | |
by demerphq (Chancellor) on Dec 10, 2001 at 18:56 UTC | |
|
Re: advice with Parse::RecDescent
by VSarkiss (Monsignor) on Dec 10, 2001 at 21:32 UTC | |
by dmmiller2k (Chaplain) on Dec 10, 2001 at 23:47 UTC | |
by demerphq (Chancellor) on Dec 10, 2001 at 21:51 UTC | |
|
Re: advice with Parse::RecDescent
by gbarr (Monk) on Dec 10, 2001 at 21:14 UTC | |
by NicS (Scribe) on Dec 10, 2001 at 22:04 UTC | |
|
Re: advice with Parse::RecDescent
by princepawn (Parson) on Dec 10, 2001 at 22:10 UTC |