- 论坛徽章:
- 0
|
how to nomalize format like that:
or use 文法 like this:
use Parse::RecDescent;
my $grammar = <<'EOG';
addition_expr: a_line(s)
| <error: illegal expression>;
a_line:'id:' line_id number(s)
{ print "\n"; }
line_id:/.+\n/
{ $item[1] =~ s/\s+$//;print "id item[1] "; }
number:/\d+\s*\n/
{ $item[1] =~ s/\s+$//;print $item[1]; }
EOG
open(DATA,"e:/perl/code/t.txt" ;
my @lines = <DATA>;;
my $text = join('', @lines);
my $parserRef = new Parse::RecDescent($grammar);
my $ret = $parserRef->;addition_expr($text);
die $@ if $@;
: ) |
|