The contents of a package are collectively called a symbol table. Symbol tables are?stored in a hash whose name is the same as the package,but with two colons
appended. The main symbol table’s name is thus %main::. Since main also happens?to be the default package,Perl provides %:: as an abbreviation for %main::.
以上引自<Programming Perl 4th>
当创建package variables 时,Perl会在对应的symbol tables(%package::)中创建对应的一个typeglob项。
code:
#!/usr/bin/perl -l
use strict;
use warnings;
{our $var = "Hello World";} ? ?#注意此处用的是our,因为my 声明的变量会存到symbol tables中
sub var{print "in sub var()"};
foreach (keys %main::){
? ? ? ? print $_ . "==>" .$main::{$_};
}
print "Done";
print "#" x 80;
print ${*var{SCALAR}};
&{*var{CODE}}();
======================================================================================================================
/==>*main::/
stderr==>*main::stderr
SIG==>*main::SIG
utf8::==>*main::utf8::
"==>*main::"
ARNING_BITS==>*main::ARNING_BITS
CORE::==>*main::CORE::
DynaLoader::==>*main::DynaLoader::
strict::==>*main::strict::
stdout==>*main::stdout
attributes::==>*main::attributes::
==>*main::
stdin==>*main::stdin
ARGV==>*main::ARGV
INC==>*main::INC
ENV==>*main::ENV
Regexp::==>*main::Regexp::
UNIVERSAL::==>*main::UNIVERSAL::
$==>*main::$
_<perlio.c==>*main::_<perlio.c
main::==>*main::main::
Carp::==>*main::Carp::
-==>*main::-
_<perlmain.c==>*main::_<perlmain.c
PerlIO::==>*main::PerlIO::
_<universal.c==>*main::_<universal.c
0==>*main::0
var==>*main::var ? ? ?#此处极为的symbol table中的对应项 BEGIN==>*main::BEGIN ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ==>*main:: @==>*main::@ _<xsutils.c==>*main::_<xsutils.c !==>*main::! STDOUT==>*main::STDOUT IO::==>*main::IO:: ==>*main:: _==>*main::_ +==>*main::+ Exporter::==>*main::Exporter:: STDERR==>*main::STDERR Internals::==>*main::Internals:: STDIN==>*main::STDIN warnings::==>*main::warnings:: DB::==>*main::DB:: <none>::==>*main::<none>:: Done ################################################################################ Hello World in sub var()