Calling a user-defined function in Perl from a variable
Yes, I needed to make such a perversion. In PHP, this is call_user_func ().
Considering that I found implementation with quite great difficulty in Google (and not where I expected it, but in calls), I decided to publish here:
#!/usr/bin/perl -w
use strict;
if(exists $ARGV[0] && exists &{$ARGV[0]}){
my $func_call = \&{$ARGV[0]};
&$func_call();
}
sub test{
print "123\n";
}
')
respectively,
./test.pl test will display 123
./test.pl aaa will not output anything
Perhaps someone will come in handy)
Source: https://habr.com/ru/post/49200/
All Articles