in reply to Re: Munging with a regex dispatch table
in thread Munging with a regex dispatch table
Which I, personally, think is preferable. The implementation of the dispatch table depends really on implementation. I like to have the name of the action as a 'key', so that the code's self-documenting, but you could also use the array aproach previously shown.my %REGEX = ( header = [qr/^(?!START:|END:)([^*: ][^:]+):(.+)\n/, \&header], starttime = [qr/^START:\s*(.+)\n/, \&etc], endtime = [qr/^END:\s*(.+)\n/, \&etc], lineitem = [qr/^(?:\* | )([^:]+):(\d+):(.+)\n/, \&etc] ); #... #You could even use constants here to make things easier. # 0 = RE; 1 = FUNCTION; or something. for my $rex_table (keys %REGEX) { if (my @m = $line =~ $rex_table->[0]) { $rex_table->[1]->($r,@m); next LINE; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Munging with a regex dispatch table
by Tanktalus (Canon) on Feb 02, 2005 at 05:15 UTC |