in reply to Use variable as a module during runtime.
You don’t need to load the file to a variable first. Just use do directly on the file:
do 'my_file.pl';
and that “executes the contents of the file as a Perl script.”
Update (in reply to Reaped: Re^2: Use variable as a module during runtime. below): If you want to use the variable, then just use eval on it:
eval $f; warn $@ if $@;
But note what the documentation says regarding scope:
The value of the expression (which is itself determined within scalar context) is first parsed, and if there were no errors, executed as a block within the lexical context of the current Perl program. This means, that in particular, any outer lexical variables are visible to it, and any package variable settings or subroutine and format definitions remain afterwards.
Hope that helps,
Athanasius <°(((>< contra mundum
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Use variable as a module during runtime.
by yoda54 (Monk) on Oct 21, 2012 at 03:11 UTC | |
by Athanasius (Archbishop) on Oct 21, 2012 at 03:40 UTC | |
by ysth (Canon) on Oct 22, 2012 at 01:40 UTC | |
by yoda54 (Monk) on Oct 22, 2012 at 23:41 UTC |
In Section
Seekers of Perl Wisdom