Perl Tip: Call variable based subroutines

Take off strict temporarily while you pipe it in the variable based subroutine calls.

{ no strict 'refs';
*{$ProdMod . "::Init"}->(\%Subroutines,$Debug);

$ProdMod is variable where subroutine call is call {$ProdMod."::Init"}. %Subroutines and $Debug are the input variables to the provided subroutine.

Also, can put it into hash or array which points to the subroutine calls as so:
my %Subs = (
"test1" => \&test1,
"test2" => \&test2,
"test3" => \&test3,
"test4" => \&test4,

And calls it:

Considering you have test1-4 subroutine defined:
sub test1($$) {...}

No comments: