in reply to Dynamic Symbol Table access

A couple of remarks. You can use symbolic references if you must, and still keep stricture on most of your program by calling { no strict 'refs'; ... } in as small a scope as you can manage.

The symbol table is a hash, and you can examine its keys with keys %Foo::Test::. To get that hash from the string you have, you must again indulge in symrefs,

use Foo::Test; my $x = 'Foo::Test' my @syms = do { no strict 'refs'; keys %{$x . '::'}; };

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Dynamic Symbol Table access
by chromatic (Archbishop) on Sep 22, 2003 at 06:12 UTC
    To get that hash from the string you have, you must again indulge in symrefs

    You can do it with real hash keys, if you know the secret:

    package Foo::Bar::Baz; use vars '$quux'; print "What should \$quux hold?\n: "; chomp( $quux = <STDIN> ); package main; use strict; my $hash = \%main::; for my $key (qw( Foo Bar Baz )) { $hash = $hash->{ $key . '::' }; } print "Quux is: ${ $hash->{quux} }\n";