BEGIN { my $varName = 'SOME_VAR'; my $varValue = 123; ## ## Dynamically create the package ## my $code = qq/ package Somepackage; use Exporter; our \@ISA = qw(Exporter); our \@EXPORT_OK = qw(\$$varName); our \$$varName = $varValue; 1; /; print $code, "\n"; eval $code; $INC{"Somepackage.pm"} = 'abc'; }
eval(STRING) should be a tool of last resort - it should certainly come after symrefs on your list of things to try.
BEGIN { my $varName = 'SOME_VAR'; my $varValue = 123; require Exporter; $INC{"Somepackage.pm"} = 1; package Somepackage; our @ISA = qw(Exporter); our @EXPORT_OK = $varName; no strict 'refs'; $$varName = $varValue; }
In reply to Re: Dynamic USE and %INC
by nobull
in thread Dynamic USE and %INC
by Bas-i
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |