Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^6: Creating dispatch table with variable in function name

by Mr. Muskrat (Canon)
on Nov 22, 2017 at 17:27 UTC ( #1204046=note: print w/replies, xml ) Need Help??

in reply to Re^5: Creating dispatch table with variable in function name
in thread Creating dispatch table with variable in function name

Add this to the script:

sub AUTOLOAD { our $AUTOLOAD; warn sprintf "unknown subroutine '%s' called with params: '%s'\n", $ +AUTOLOAD, join "', '", @_; }

{ bar => sub { ... }, foo => sub { ... }, zot => sub { ... } }
unknown subroutine 'main::_x_zot' called with params: ''
hi from main::_x_foohi from main::_x_bar

Update: Yes, dynamically generated dispatch tables can cause problems if you aren't careful but that's true enough without them too. You can protect against most (all?) of the potential issues if you try. I'm not going to tell anything that they should or should not use dynamically generated dispatch tables in production. I do want to provide enough information for someone to be able to make that decision for themself.

Replies are listed 'Best First'.
Re^7: Creating dispatch table with variable in function name
by AnomalousMonk (Archbishop) on Nov 22, 2017 at 17:43 UTC

    That might actually be worse. Instead of coming to a screeching halt, the process would produce a warning message that might get tucked away in an error log somewhere and go unnoticed for days/weeks/months/years/ever.

    Give a man a fish:  <%-{-{-{-<

      The whole point of that post was to show that you can choose how to deal with it.

        Agreed, but the point of my posts was to show why I would be inclined to approach the whole problem in a different way, i.e., by avoiding symbolic manipulations altogether.

        Give a man a fish:  <%-{-{-{-<

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1204046]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2023-12-10 00:39 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (38 votes). Check out past polls.