As others have said, a dispatch table is almost certainly the way to go. But, of course, there's more than one way to symbolically dereference a subroutine in compliance with strictures
use strict; sub foo { print "this is foo(@_)\n" } sub bar { print "this is bar(@_)\n" } __PACKAGE__->can($_)->('invoked via can()') for qw/ foo bar /; ( \&$_ )->('invoked without a temp var') for qw/ foo bar /; __output__ this is foo(invoked via can()) this is bar(invoked via can()) this is foo(invoked without a temp var) this is bar(invoked without a temp var)
In the first instance we're executing the subroutine returned by UNIVERSAL, and in the second instance we're creating a sub reference and then executing (the parens are necessary for syntactical disambiguation).
HTH

_________
broquaint


In reply to Re: calling a sub using a variable's value by broquaint
in thread calling a sub using a variable's value by rvosa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.