Is it possible to call a procedure in Perl 6 when we have the name as a string?
sub AAA { say "ok"; }
my $sub = "AAA";
# &$sub(); or something ?
I know that a dispatch table is a better idea:
my %table; %table<a> = &AAA();
&(%table<a>); # Execute "AAA"
I ask because calling a method where we have the name as a string is possible:
say pi."$_"() for <Int Real Str>;
You can use indirect name lookup:
sub AAA { say "ok"; }
my $sub = "AAA";
&::($sub)();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With