Esteemed Monks,

We have files that arrive in a directory and from the name of each file we extract a string $function . This is a function name defined in a module.

We then build a command with that $function and do an eval on it.
The reason we do this is because the files, functions, and modules holding them are defined by some other people so it's convenient for us : we just drop their modules in our lib directory and processing of new file types is automatic .

But we do this a lot of time (there are many files) and I've heard that eval is not good and not very performant.
Also this looks like the $$value problem, ie "i want to get a variable value from another variable" which, as i've seen here in the monastery, should be replaced by a hash solution .

Should we avoid the eval ?
Should we do &$function ? (no strict )
Should we do something else ?

Thanks for your advices !


In reply to Calling a sub from a variable ? by ZlR

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.