in reply to Interpolating Variables as Package Names
Update: Ok, I worked it out:
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.use strict; use warnings; package foo; our $var = 'got it'; package main; my $pkg = 'foo'; my $v = 'var'; print ${$main::{$pkg.'::'}{$v}};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Intropating Variables as Package Names
by dReKurCe (Scribe) on Mar 09, 2005 at 22:31 UTC |