in reply to Naming Subs

You can do almost exactly what your pseudo-code suggests, using code references. (see perlref manpage for more on refs.) The idea is that the variable is evaluated, then execution passes to the subroutine with that name, if one exists:
$data = &{ $action };

Of course you'd want to catch actions that haven't been defined; you could do that by comparing $action against a hash of defined actions, or eval'ing the above statement, or, well, you know how it goes ;)

Replies are listed 'Best First'.
Re: Re: Naming Subs
by BrowserUk (Patriarch) on Jan 13, 2003 at 11:40 UTC

    Of course you'd want to catch actions that haven't been defined; you could do that by comparing $action against a hash of defined actions, or eval'ing the above statement, or, well, you know how it goes ;)

    No need for any of that. If you used a hash, you would need to verify that the element existed using exists. As pointed out elsewhere in thread, the symbol table is just a glorified hash anyway, and you can check for the existance of the action in exactly the same way

    $data = &{ $action } if exists &{ $action };

    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.