Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by Mr. Muskrat (Canon)
on Nov 22, 2017 at 17:27 UTC ( [id://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 "', '", @_; }

Output:
{ 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-29 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found