in reply to How to make a variable in hard call.

You could use string eval, if I understand your question correctly.

use strict; use warnings; use Test::More; sub square { my $num = shift; return $num*$num; } my $subname = 'square'; is( eval "&$subname(4)", 16 ); done_testing;

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: How to make a variable in hard call.
by ikegami (Patriarch) on May 09, 2023 at 08:24 UTC

    Same without eval:

    do { no strict "refs"; $subname->( 4 ) }
    We can also use some trickery:
    ( \&$subname )->( 4 )
Re^2: How to make a variable in hard call.
by SankoR (Prior) on May 08, 2023 at 01:31 UTC
    Designing their code based on this means every time they wanted to write data to a pin there would be a string eval slowing everything down.