Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
What problem were you trying to address when you wrote this?

Modularity, Maintenance - the usual suspects. Exporter::Dispatch isn't really aimed at dispatch tables of 3 or 4 subs of 1 line a piece - its aimed for use with large dispatch tables. For instance, the last time I used it was on a project with 4 dispatch tables, each having between 10-30 subroutines, with each subroutine varying in length from 10-60 lines.

As for closing over lexical variables, you can still do that if the subs are in a separate package - you just put the declaration in the same package as the rest of the dispatch table subs are defined!

But, as for:

And a further hash advantage - you are allowed names that would not easy or (in some cases) legal in Perl function names.

What does that buy you? The only time I think I've ever used a dispatch table that had non-word dispatch names was this:

my %op_table = ( '+' => sub { $_[0] + $_[1] }, '-' => sub { $_[0] - $_[1] }, '*' => sub { $_[0] * $_[1] }, '>' => sub { $_[0] > $_[1] }, '<' => sub { $_[0] < $_[1] }, '=' => sub { $_[0] == $_[1] }, # this is the one oddball; # otherwise i could just eval'ed.. +. '<=' => sub { $_[0] <= $_[1] }, '>=' => sub { $_[0] >= $_[1] }, '!=' => sub { $_[0] != $_[1] }, );

This was part of a very simple simulator that I wrote for a language that we have compiled down to 68HC11, and the only reason I wrote it this way was so I could use the raw token as the hash key.


In reply to Re^5: A short, "iffy" rant by jryan
in thread A short, "iffy" rant by Ovid

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 scrutinizing the Monastery: (3)
As of 2024-03-29 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found