in reply to String parsing
Your data lines are different enough that each type needs its own parser. A hash of coderefs ("dispatch table") will do that nicely,
parse_line() should be called in list context, too.my $parser = { OFF => sub {()}, SUCCESS => sub { local $_ = shift; /\((\w*)\)/ }, # call these in list context! ERROR1 => sub { local $_ = shift; /disk number \((\d+)\) at \((\d+:\d+)\)/; }, WARNING1 => sub { local $_ = shift; /(\w.*)^/; } }; sub parse_line { local $_ = shift; my ($key, $data) = split ':', $_, 2; $key =~ tr/()//d; ($key, $parser->{$key}->($data)); }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String parsing
by Abigail-II (Bishop) on Jan 05, 2004 at 12:35 UTC |