|go ahead... be a heretic|
How to de-reference a coderef?by AndyH (Sexton)
|on Dec 09, 2004 at 14:52 UTC||Need Help??|
AndyH has asked for the
wisdom of the Perl Monks concerning the following question:
As usual, my attempts to keep a question short introduced confusion rather than clarity. So, I should explain more clearly what I am trying to do.
I have a complex data structure, a hash of hashes and arrays, that describes a set of menus for a CGI application. For each menu item, there is the text of the menu, the link text, the user documentation and the reference to the subroutine to be run when the menu entry is chosen.
A "parser" generates the appropriate menus and also handles when a menu item is chosen, as this might be a subroutine, another menu or a different URL entirely. If a subref entry exists in the hash, it calls the subroutine. WHat I needed was for the parser code to be able to get at the name of the subroutine before calling it, to allow for debug, context-sensitive help etc.
As usual, also, the superb perlmonks response produced not only rapid way of doing what I needed to do but also a thoguth-provoking discussion on other ways of doing it, doing the whole thing differently, and the meaning of perl life. Thanks to the monks.