blazar has asked for the wisdom of the Perl Monks concerning the following question:

Sorry, I couldn't find a better subject...

Well, perl -le 'print for keys %::' gives me:

^R
^X
"
$
+
-
/
0
<none>::
@
ARGV
CORE::
DB::
DynaLoader::
ENV
INC
IO::
Internals::
PerlIO::
Regexp::
STDERR
STDIN
STDOUT
UNIVERSAL::
_
_<-e
_<perlio.c
_<perlmain.c
_<universal.c
_<xsutils.c
attributes::
main::
stderr
stdin
stdout
utf8::
Now the question is: I understand why most of those are there, but there are some that I can't quite make sense of. Specifically:

20050508 Unconsidered by Corion: Was edit:26 keep:18 del:0,Considered: friedo: Change title to "Default symbol table in main" or similar

Replies are listed 'Best First'.
Re: keys %::
by dave_the_m (Monsignor) on Apr 29, 2005 at 10:19 UTC
    what are the lowercase qw/stderr stdin stdout/ for
    They're deprecated aliases for STDERR etc.
    What do the _<-ones mean
    They're for the debugger; see perldebguts.pod for the gory details
    precisely when and where the destructor is used
    No idea, but the destructor itself is a NOOP.

    Dave.

Re: keys %::
by Animator (Hermit) on Apr 29, 2005 at 11:51 UTC

    A better subject would be something similar to: 'Symbol table of the main-package'...

    Update: I should have know that mentioning that %:: is the symbol table of the package main and that it therefor is a better title would get downvoted....
    Noone cares how it is called right?

    Now I really wonder why I stopped posting a few months ago...

      Update: I should have know that mentioning that %:: is the symbol table of the package main and that it therefor is a better title would get downvoted.... Noone cares how it is called right?
      FWIW it wasn't me to downvote you, if not for anything else because I don't have votes left for today...

      I think you got downvoted because you only made a cmt about the subject with no positive content re the actual question. I say so because something similar happened to me in the past. We may both dislike this kind of things but this is a community after all, so we have to accept its rules if we like to take part to it...

        'tisn't a rule.

      No but there are better ways of indicating that the subject should be changed like "considering" the node or messaging the author. That's why I downvoted it.

      /J\

      This is actually the root of the symbol table, isn't it? You might notice that 'main::' is included in the listings everyone posted.

      mhoward - at - hattmoward.org
Re: keys %::
by deibyz (Hermit) on Apr 29, 2005 at 11:03 UTC
    If it helps, Cygwin and Solaris output:
    bash-2.03$ perl -le 'print for sort keys %::' CYGWIN_NT-5.1 Solaris ============== ======= " " $ $ + + - - / / 0 0 <none>:: <none>:: @ @ ARGV ARGV CORE:: CORE:: Cwd:: DB:: DB:: DynaLoader:: DynaLoader:: ENV ENV INC INC IO:: IO:: Internals:: Internals:: PerlIO:: PerlIO:: Regexp:: Regexp:: STDERR STDERR STDIN STDIN STDOUT STDOUT UNIVERSAL:: UNIVERSAL:: _ Win32:: _<-e Win32CORE:: _<perlio.c _ _<perlmain.c _<Win32CORE.c _<universal.c _<cygwin.c _<xsutils.c _<perlio.c attributes:: _<perlmain.c main:: _<universal.c stderr _<xsutils.c stdin attributes:: stdout main:: utf8:: stderr stdin stdout utf8::
Re: keys %::
by tphyahoo (Vicar) on Apr 29, 2005 at 10:45 UTC
    Neato. On my system (WinXP, ActiveState) I get
    / stderr _<.\win32.c _<perllib.c utf8:: " CORE:: DynaLoader:: stdout attributes::  stdin ARGV INC ENV Regexp:: _<..\perlio.c UNIVERSAL:: $ main:: - Win32:: PerlIO:: _<..\universal.c 0  @ _<..\xsutils.c STDOUT IO::  _ + STDERR Internals:: STDIN DB:: <none>::
    Wish I could draw some brilliant conclusion from that... well, I do notice that, with regards to the .c files that get mentioned, with ActiveState you get perllib.c and win32.c instead of perlmain.c.
Re: keys %::
by ysth (Canon) on Apr 29, 2005 at 17:01 UTC
    I believe, but am not certain, that the only purpose of the empty Regexp::DESTROY is saving Perl the time and trouble of looking for UNIVERSAL::DESTROY, Regexp::AUTOLOAD, and UNIVERSAL::AUTOLOAD whenever a qr// is freed.
Re: keys %::
by johnnywang (Priest) on Apr 29, 2005 at 20:28 UTC
    I changed it to also print out the values, and am delighted to find:
    # on cygwin perl -e 'print "$_ => $::{$_}\n" for keys %::' __OUTPUT__ / => *main::/ stderr => *main::stderr _<.\win32.c => *main::_<.\win32.c _<perllib.c => *main::_<perllib.c utf8:: => *main::utf8:: " => *main::" CORE:: => *main::CORE:: DynaLoader:: => *main::DynaLoader:: stdout => *main::stdout attributes:: => *main::attributes:: &#8597; => *main::&#8597; stdin => *main::stdin ARGV => *main::ARGV INC => *main::INC ENV => *main::ENV Regexp:: => *main::Regexp:: _<..\perlio.c => *main::_<..\perlio.c UNIVERSAL:: => *main::UNIVERSAL:: $ => *main::$ main:: => *main::main:: - => *main::- Win32:: => *main::Win32:: PerlIO:: => *main::PerlIO:: _<..\universal.c => *main::_<..\universal.c 0 => *main::0 => *main:: @ => *main::@ _<..\xsutils.c => *main::_<..\xsutils.c STDOUT => *main::STDOUT IO:: => *main::IO:: &#8593; => *main::&#8593; _ => *main::_ + => *main::+ STDERR => *main::STDERR Internals:: => *main::Internals:: STDIN => *main::STDIN DB:: => *main::DB:: <none>:: => *main::<none>::
    This "confirms" what I read somewhere that the symbol table contains the typeglob of the key, which apparently works for any package. Is there anyway to find out what the typeglobs really are? (i.e, its scalar value, array value, etc.)

      Yes... to see if something is a scalar you can do *something{SCALAR}. if it is a scalar then it will exists and it will be defined... (read `perldoc perlmod` if you need more information)

      Or you could use the Devel::Symdump package...

        I seem to recall that every glob has an SV in the scalar slot as an optimization, but I can't confirm it by reading the source code. (I'm not sure I've even found the right spot in the code.)

      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" }
        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" } }