原帖由 fayland 于 2005-12-5 11:00 发表
这个在 骆驼书 第十章 包 的符号表里有讲的。
原帖由 思平 于 2005-12-5 10:43 发表
our %sym = (
name => 'hoowa',
age => 28,
sex => 'man',
);
print ${*{$::{sym}}{HASH}}{name};
会打印出 hoowa,为什么?
原帖由 思平 于 2005-12-5 10:43 发表
our %sym = (
name => 'hoowa',
age => 28,
sex => 'man',
);
print ${*{$::{sym}}{HASH}}{name};
会打印出 hoowa,为什么?
原帖由 兰花仙子 于 2005-12-5 18:59 发表
Perl的本质,就是一切皆为符号,而符号的本质就是引用,所以perl的本质就是一切皆为引用。
这是仙子说的,大家有意见,可以在此反驳偶,嘿嘿。
你的语法错误....
{} 回传的是一个ref to hash的引用....你把他负值给hash...是会有问题的....
$glob其实就是等於一个ref to typeglob 也可以把他看成pointer...
透过${$glob}可以将$glob指向hash的实际位址
你就可以利用${$glob}{a}取值...
用C的pointer可以很容易解释这些问题 ...
只是有些在C里面不合道理的.type cast问题...在perl是正确的.不需要理会type cast问题..
原帖由 兰花仙子 于 2005-12-6 20:14 发表
无我无相,四大皆空。
读读禅经,或许有助于理解,
**main::sym is a syntax error, but *{*main::sym}==*main::sym.
But don't be fooled by the equality $::{sym} == *main::sym. It just
means they numerically compare the same. Taking references you get
that $::{sym} returns a scalar and *main::sym a glob.
$ perl -e 'print \($::sym, *main::sym)'
SCALAR(0x1002f094)GLOB(0x10010fa8)
So *{$glob} is the way to tell Perl to go from the scalar to the glob,
when we'll be able to access its HASH part.
That's why
$ perl -e 'our %sym = (name => "flower"); print ${*{$::{sym}}{HASH}}{name};"
prints "flower", but
$ perl -e 'our %sym = (name => "flower"); print ${$::{sym}{HASH}}{name};"
prints nothing ($::{sym}{HASH} returns undef). As Wiggins wisely said,
$sym->{name} is more sane.
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |