in reply to Interpolating Variables as Package Names

use is done at compile time in a BEGIN block. If you want to dynamically load a package at run time, you want require instead. The below code worked for me:
#!/usr/bin/perl; unshift @INC, "/path/to/package"; print "Interpolate variables from which package? "; $package = <STDIN>; chomp($package); eval "require $package"; print <<EOF; This variable: $package::variable (actually this doesn't work) originates in package $package. EOF

Update:: gaal is absolutely right, the code will not show the correct package variable. I was more focused on showing how to load modules at runtime. Roy Johnson seems to have the interpolation part worked out.

Replies are listed 'Best First'.
Re^2: Intropating Variables as Package Names
by gaal (Parson) on Mar 09, 2005 at 20:27 UTC
    $package::variable looks for a dynamic variable called $variable in the package package::. As Roy Johnson said, you need to look in the symbol table of $package.