in reply to Call subroutine by reference ?
This is typically a hash whose keys are the text that is used to identify which sub to call, and the value is a reference to the sub.
Update: Added check for "existence" as recommended by sundialsvc4 (++), below. (Also fixed text typo).my %Dispach_table = ( UNO => \&Process_One, DOS => \&Process_Two, TRES => sub { print "This is an example of an in-line subref\n"}, ); sub Process_One{ #whatever } sub Process_Two{ # Some code } my $var = "DOS"; # Invoke the dispatch (after verifying it exists) $Dispatch_table{ $var } or die "ERROR: attempt to dispatch non-existin +g entry: '$val'"; $Dispatch_table{ $var } -> ( #Parameters, if any ); # Here is where the routine gets called.
"I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
-- Dr. Cox, Scrubs
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Call subroutine by reference ?
by locked_user sundialsvc4 (Abbot) on May 31, 2013 at 10:48 UTC | |
|
Re^2: Call subroutine by reference ?
by JockoHelios (Scribe) on May 31, 2013 at 17:09 UTC |