in reply to Speed vs Laziness
Now the execution engine would look like:my @actions = ( qr/thingy(with)parens(to)boot/ => sub { do this }, qr/smile(and)frown/ => [sub { do this }, sub {and this }], qr/another(one)bites(the)dust)/ => undef, );
I'm sure you can figure out where to make these object instance variables. Hope this helps.$_ = some line; my @tmp = @actions; while (@tmp) { my ($qr, $ops) = splice @actions, 0, 2; if (my @matches = /$qr/) { if (not defined $ops) { $default->(@matches); } elsif (ref $ops eq 'CODE') { $ops->(@matches); } elsif (ref $ops eq 'ARRAY') { $_->(@matches) for @$ops; } else { die "bad" } last; } }
-- Randal L. Schwartz, Perl hacker
|
|---|