in reply to Re: Subroutines in Dispatch Tables
in thread Subroutines in Dispatch Tables
Update: I guess it is obvious, but if you cycle down this action list running regex'es, the sub hello_me will not get executed because word chars are _a-z0-9 (all of the things can be in a Perl identifier). In other words all digits are "word characters".#!/usr/bin/perl use warnings; use strict; my @dispatch_tables = ( { regex => qr/\w+/, action => sub { print "aaa\n" }, }, { regex => qr/\d+/, action => \&hello_me, }, ); $dispatch_tables[0]->{action}->(); $dispatch_tables[1]->{action}->( "1", "2" ); sub hello_me { print "hello me: @_\n"; } __END__ aaa hello me: 1 2
I don't know what the "full" application will be like but I would be thinking of using a couple of simple structures, this table being the simple "action" hash for a particular case. 'onlydigits' => sub {}, 'mixed_alphanum' => sub{}. There would another structure to decide what case/situation that you are in. Here it is obvious what the regex does, the actual app may not be so simple and an "extra" level of translation may provide some documentation value.
|
|---|