in reply to subroutine ref while "strict refs"
Hi,
in you current use case I would also recommend to use a dispatching table as Anonymous monk adviced.
But the following self contained examlple should show you a way to achieve what you want to do without warnings:
#!/usr/bin/perl use strict; use warnings; use 5.010; use Carp; my $ref = get_func_reference('my_check_func'); # call it $ref->('To check'); sub my_check_func { my ($param) = @_; $param //= ''; say "Check: $param"; } sub get_func_reference { my ($function_name) = @_; $ref = \&{$function_name}; unless(defined(&$ref)) { confess "ERROR: No function defined for name '$function_name'. +\n"; } return $ref; }
Regards
McA
|
|---|