Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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 "', '", @_; }

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 (Chancellor) 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
Node Status?
node history
Node Type: note [id://1204046]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-07-16 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (330 votes). Check out past polls.

    Notices?