in reply to typeglob/symbolic reference question
Hmmm...maybe the answer to my first post is simply: you can assign to a type glob, *{"color"}, but you can't assign to a subroutine, &{"color"}.
Therefore, if you have a string and you want to dynamically define a function of the same name and then execute the function, you can:
1) Use the string to retrieve a typeglob and then assign a subroutine to the typeglob, which serves to define the function.
*{"do_stuf"} = sub {print "hello"};
2) Subsequently, use the the string as a symbolic reference to retrieve the function and execute it.
&{"do_stuff"}();
|
---|
In Section
Seekers of Perl Wisdom