in reply to Calling func named in string

TIMTOWTDI

Just stick your internal functions in their own package and use the package hash :)

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11163188 use warnings; use List::AllUtils qw( sample ); (sample 1, values %INTERNALFUNCTIONS::)->() for 1 .. 5; package INTERNALFUNCTIONS; sub TestSub1 { print "TestSub1\n"; } sub TestSub2 { print "TestSub2\n"; }

Outputs:

TestSub1 TestSub2 TestSub2 TestSub1 TestSub1

Still strict, no fancy manipulations required, and you can dynamically add more functions :)
Perl sure has some interesting tricks up its sleeve.

Replies are listed 'Best First'.
Re^2: Calling func named in string
by LanX (Saint) on Dec 18, 2024 at 07:38 UTC
    Yes but be careful not define any other package vars in INTERNALFUNCTIONS::

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery