What worries me is that, while strict is perfectly happy with it, the code below has a run-time error that may not be triggered for hours/days/weeks/months/...
Okay... So does the equivalent static dispatch table.
use strict; use warnings; ;; sub hiya { print 'hi from ', (caller(1))[3]; } ;; sub _x_foo { hiya; }; sub _x_bar { hiya; }; ;; my %disp = ( foo => \&_x_foo, bar => \&_x_bar, zot => \&_x_zot, ); dd \%disp; ;; $disp{foo}->(); $disp{zot}->(); $disp{bar}->();
You have to write code for each piece in order for the whole thing to work reliably, but you may not discover that it doesn't until a very inopportune moment. If everything could be thoroughly tested prior to deployment, the queasy feeling in my stomach might be eased a bit, but even so...
This is true for all Perl code though. There's a gajillion ways to write a script that "compiles" with strictures enabled but fails at runtime. This is why we write tests (unit, functional, etc).
In reply to Re^6: Creating dispatch table with variable in function name
by Mr. Muskrat
in thread Creating dispatch table with variable in function name
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |