I wish to have a hash containing references to sub-functions where I can call those functions dependent upon a user defined variable, I will try and give a simplified example of what I’m trying to do.
my %colors = (
vim => setup_vim(),
emacs => setup_emacs(),
)
$colors{$editor}(arg1, arg2, arg3)
where setup_vim() and setup_emacs() would be sub-functions defined later in my file and $editor is a user defined variable (ie vim or emacs). Is this possible? I can’t get it working, or find good information on the subject. Thanks.
(Note I have it implemented right now as a working Switch, but I think a hash like the above would make it easier to add new entries to my existing code)
Here is the syntax.
Note that you can actually create functions directly with
And if you’re familiar with closures, Perl supports full closures for variables that have been declared lexically, which you can do with my.