in reply to Calling $function from $module
is$invocant->$method_name( @args )
or($module.'::'.$function_name)->( @args ) # Perl 5.6+
&{ $module.'::'.$function_name }( @args )
use strict qw( refs ); forbids these (as it should), so you can use the following:
my $ref = do { no strict qw( refs ); \&{ $module.'::'.$function_name } }; $ref->( @args )
Except it turns out that \&{...} is exempt from strict reference enforcement, so you can simply use
my $ref = \&{ $module.'::'.$function_name }; $ref->( @args )
or even
( \&{ $module.'::'.$function_name } )->( @args )
This trick to bypass strict reference enforcement is not documented.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calling $function from $module
by stevieb (Canon) on Aug 05, 2015 at 23:11 UTC | |
by Anonymous Monk on Aug 05, 2015 at 23:13 UTC | |
by stevieb (Canon) on Aug 05, 2015 at 23:32 UTC | |
by ikegami (Patriarch) on Aug 07, 2015 at 20:34 UTC | |
|
Re^2: Calling $function from $module
by Anonymous Monk on Aug 06, 2015 at 00:13 UTC |