in reply to Calling variable variables
Of course, you'll have to do a little homework on glob slots (the SCALAR thingie), and you'll have more work to do if you have multi-level package names, but that should get you started.use strict; package Foo; use vars qw( $foo ); $foo = 100; package Bar; use vars qw( $foo ); $foo = 200; package Baz; use vars qw( $foo ); $foo = 300; package main; my $package = (qw( Foo Bar Baz ))[ int rand 3 ]; my $foo = $main::{"${package}::"}{foo}; $foo = ${ *{$foo}{SCALAR} }; print "($foo)\n";
Update: Technically, this is a symbolic reference. I should have said that you can use a symbolic reference that doesn't set off strict 'refs' alarms.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Calling variable variables
by erikharrison (Deacon) on May 26, 2002 at 07:33 UTC | |
by Juerd (Abbot) on May 26, 2002 at 13:16 UTC | |
by Anonymous Monk on May 26, 2002 at 15:04 UTC |