加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl symbol table

发布时间:2020-12-16 00:09:55 所属栏目:大数据 来源:网络整理
导读: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
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()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读