Greetings, O monks,
I am having difficulty using references in the context of a method call I am using. For example, this code (stolen from here) works perfectly:
use RTF::Writer; my $rtf = RTF::Writer->new_to_file("greetings.rtf"); $rtf->prolog(); $rtf->paragraph( "Hi there!" ); $rtf->close;
I would like to know how to use a reference in place of $rtf. Specifically, I would like to able to retrieve the string "rtf" from somewhere else, and then call $(insert string here)->... My best guess on how to do this, after consulting perlmod, would be something like this:
use RTF::Writer; my $rtf = RTF::Writer->new_to_file("greetings.rtf"); my $foo = "rtf"; ${$foo}->prolog(); ${$foo}->paragraph( "Hi there!" ); ${$foo}->close;
As it currently stands, the above returns an error. "use diagnostics;" reveals that the value of ${$foo} is undefined. Upon further research, I have determined that using symbolic references in this context is destined to fail. This page talks about using hashes as references for functions, but I haven't been able to find anything on method calls that are stored as scalars, as in the first example code above.
My short term goal is to figure out the correct code to replace ${$foo} in the second code block above. Any help would be greatly appreciated!
In reply to Symbolic Reference in Method Call by EclecticScion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |