in reply to Traversing variables in a namespace

You can get the names of the variables from main with '%::'. I use eval to extract the values:
for $name (keys %::) { eval 'my $val = '.$name.';'; }
Hope this helps,

Jeroen
"We are not alone"(FZ)

Replies are listed 'Best First'.
Re: Re: Traversing variables in a namespace
by MeowChow (Vicar) on Feb 06, 2001 at 03:37 UTC
    Using eval is overkill in this case. It is more efficient and probably more straightforward to disable strict 'refs' and use symbolic reference to extract a variable's value from the symbol table:
    for $name (keys %::) { no strict 'refs'; $val = $$name; }
       MeowChow                                               
                    print $/='"',(`$^X\144oc $^X\146aq1`)[-2]
      If you remember that %main:: is a hash of globs, then a simple derefence works, doesn't worry strict and allows you to get all types of vars. But you may only want scalars, and not a scalar version of almost everything.
      for (keys %main::) { $val = ${ *{ $main::{$_} }{SCALAR} }; }