in reply to Interpolating Variables as Package Names

I'm dumping my previous answer in favor of pointing you here. At least until I figure out a concise answer.

Update: Ok, I worked it out:

use strict; use warnings; package foo; our $var = 'got it'; package main; my $pkg = 'foo'; my $v = 'var'; print ${$main::{$pkg.'::'}{$v}};
Note that you get no hassles about symbolic references. "main::" is the name of the hash that includes the symbol tables for all the other packages. You index it by the package name (with double-colon appended), and then the variable name. That gives you a glob reference, which you can dereference using the appropriate sigil.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Intropating Variables as Package Names
by dReKurCe (Scribe) on Mar 09, 2005 at 22:31 UTC
    An amazing solution!Thanks for the help!