Can you please explain how does this line work? $func->(%opts);
This line $func->(%opts) do not have any return statement; But it returns the value properly
ThanksCode: #!/usr/local/bin/perl use strict; use Getopt::Long qw(:config gnu_getopt); ########################################### # Parses the commad line arguments # Example: callfunction.pl -action getInfo ########################################### sub parse_args { my %opts; GetOptions(\%opts, "action=s", ); return %opts; } my %opts = parse_args(); my $action = $opts{action}; my $output = call_function($action, %opts); =head call_function ($function_name, %params) This method invokes the appropriate subroutine based on the funcname p +assed =cut sub call_function { my $funcname = shift; my %opts = @_; my $package = 'main'; if ( my $func = UNIVERSAL::can($package, $funcname) ) { $func->(%opts); } else { die "no such function $package\::$funcname\n"; } } sub getInfo { my $msg = shift; return $msg; }
In reply to How to invoke the method dynamically using universal::can by vmraj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |