Perl-Sensitive Sunglasses | |
PerlMonks |
Re^3: Use variable as a module during runtime.by Athanasius (Archbishop) |
on Oct 21, 2012 at 03:40 UTC ( [id://1000169]=note: print w/replies, xml ) | Need Help?? |
In your original code, $f was a variable holding the whole code of the module as a string. So of course
would produce syntax errors! You need to replace $f with whatever name you gave the module, i.e., the name you used in the package declaration. Here is an example to show how this works: (1) File “Widget.pm”:
(2) The main .pl script (in the same directory as Widget.pm):
When I run this, I get:
as expected. Athanasius <°(((>< contra mundum
In Section
Seekers of Perl Wisdom
|
|