Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Just to give some more weight to one of the choices, I would go with davorg's suggestion to create a dispatch table. That is the type-safest method, because you've presumably validated the functions you're putting into the dispatch table. In addition, it's easier to work with, as the functions are just values in a data structure you can iterate over, etc.

The no strict 'refs'; suggestion, while the easiest to implement (you just put a block around the call and add no strict 'refs'; at the top) ... it doesn't solve the issue. All you end up doing is patching around the problem. strict is, well, strict ... for a reason.

The eval suggestion, while canonical, is, in my opinion, also a patch. eval is extremely powerful, but it doesn't give you the greatest amount of control over what's happening. There are a number of cases where you would have to use it, cause there simply isn't any other sane way to do what you have to do. But, if you can do something in a sane and maintainable manner that doesn't use eval, I'd suggest doing that. eval is one of the less-understood features of Perl. The poor schmuck who has to read your code after you're hit by that truck will remember you fondly if you try to minimize his/her learning curve. :-)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


In reply to Re: Strict, strings and subroutines by dragonchild
in thread Strict, strings and subroutines by hatter

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found