in reply to Dynamic USE and %INC
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dynamic USE and %INC
by Bas-i (Initiate) on Mar 17, 2005 at 21:52 UTC | |
by nobull (Friar) on Mar 29, 2005 at 16:19 UTC |