At some point in their life, every programmer decides that, for the problem at hand, the best solution is to create a set of functions and pass their names as variables. It's not.
First, its a security hazard, as users' input should never be used to execute code in your programs. Second, since code doesn't write itself, the functions themselves have to be written and named, so the actual "variable named after function/function named after variable" scheme isn't much different than foo() if (/foo/).
This pseudo-"functional programming" is better written as a hash with the variable name as key and a function ref as value, similar (but not limited) to this example:

use strict; use warnings; my %hash = ( foo => sub {return "foo\n"}, bar => sub {return "bar\n"}, ); print &{$hash{'foo'}};

Also, with single quotes, 'foo\n' prints foo\n rather than "foo" and a newline.

Software speaks in tongues of man.
Stop saying 'script'. Stop saying 'line-noise'.
We have nothing to lose but our metaphors.


In reply to Re: Invoke sub whose name is value of scalar by Erez
in thread Invoke sub whose name is value of scalar by andreas1234567

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.