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
In reply to Re: Call subroutine by reference ?
by NetWallah
in thread Call subroutine by reference ?
by JockoHelios
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |