in reply to Re: keys %::
in thread keys %::

Is there anyway to find out what the typeglobs really are? (i.e, its scalar value, array value, etc.)

Each slot in the GLOB, if defined, contains a reference to the actual value. The following works for looking up scalars, arrays, and hashes:

for my $g(sort keys %::) { print "$g:\n"; if(defined( *{$g}{SCALAR} ) ) { print " SCALAR: ", ${ *{$g}{SCALAR} }, "\n"; } if(defined( *{$g}{ARRAY} ) ) { print " ARRAY: ", join ", ", @{ *{$g}{ARRAY} }, "\n"; } if(defined( *{$g}{HASH} ) ) { print " HASH: "; while(my ($k, $v) = each %{ *{$g}{HASH} } ) { print "$k => $v, " } } print "\n" }

Replies are listed 'Best First'.
Re^3: keys %::
by Sec (Monk) on Jul 20, 2005 at 12:43 UTC
    I have improved this script a bit, it can recurse into symbol tables now.
    I learned something new today. Internals::SvREADONLY can reset the readonly flag :)
    my $table=shift||''; $table.="::"; dumptable($table); sub dumptable{ my $table=shift; my $indent=shift||''; while (my ($key,$value)=each %$table ){ print qq!$indent"$key":\n!; if(defined(*{$value}{SCALAR}) and defined(${ *{$value}{SCALAR}})){ print "$indent\tSCALAR: ",${*{$value}{SCALAR}}, "\n"; } if(defined( *{$value}{ARRAY} ) ) { print "$indent\tARRAY: ", join ", ",@{*{$value}{ARRAY}}, "\n"; } if(defined( *{$value}{HASH} ) ) { if ($key =~ /::$/){ print "$indent\tSYMTAB:\n"; dumptable($value,"\t".$indent) if (*{$value}{NAME} ne "main::"); }else{ print "\tHASH:\n"; while(my ($k, $v) = each %{ *{$value}{HASH} } ) { print "$indent\t\t$k => $v,\n" } } } if(defined( *{$value}{CODE} ) ) { print "$indent\tCODE: ",*{$value}{CODE},"\n"; }; if(defined( *{$value}{IO} ) ) { print "$indent\tIO: ",*{$value}{IO},"\n"; }; print "\n" } }