I save the name of the routine that I want to call at runtime in a variable called $ action. Then I use this to call this sub at the right time:
&{\&{$action}}();
It works great. The only thing I don't like is that it is ugly, and every time I do this, I feel obligated to add a comment for the following developer:
Does anyone know a more beautiful way to do this?
UPDATE: The idea here was to avoid having to maintain a submit table every time I added a new sub called, since I am the only developer, I don’t worry about other programmers following or not following the “rules”. Donate a little security for my convenience. Instead, my dispatch module would check $ action to make sure that 1) it is the name of a particular routine and not malicious code to run with eval, and 2) that it will not run any sub marked with an underscore to be marked as internal subtitles in accordance with this naming convention.
Any thoughts on this approach? The whitelist list routines in the dispatch table are something that I will forget all the time, and my clients would prefer that I make a mistake on the side of “it works” than “it is unholy”. (very limited time for application development)
FINAL UPDATE: I still decided that I decided on the control desk. Although I would be curious if anyone who reads this question has ever tried to end this and how he did it, I should bow to collective wisdom here. Thanks everyone, many great answers.
perl
Marcus Dec 16 '09 at 16:00 2009-12-16 16:00
source share