我是Perl新手。我知道$
是一個標量,@
是一個數組,而%
是一個哈希。
我已經看到了一個類似的代碼(我的記憶寫):
$var = { key => value, anotherkey => anothervalue }
這個數組,哈希還是標量?
這是什麼?
我是Perl新手。我知道$
是一個標量,@
是一個數組,而%
是一個哈希。
我已經看到了一個類似的代碼(我的記憶寫):
$var = { key => value, anotherkey => anothervalue }
這個數組,哈希還是標量?
這是什麼?
即聲明瞭一個標量變量$var
含有參考到匿名散列。
引用(有點像指針)總是標量的,不管它們引用的是什麼。
你也可以這樣做:
%hash = (key => value, anotherkey => anothervalue); #parentheses, not curlies!
$var = \%hash;
在這種情況下,通過$var
引用的哈希不再是匿名的,但結果卻是另有相同。
您可以通過提領$var
與->
將散列標{
之前提取所引用的散列的單個元素... }
語法:
$var->{key} # == value, same as $hash{key} in second case
或者你可以檢索整個事情(和恢復%hash
)via %{$var}
。
查看更多詳情here。
它是對散列的引用。請參閱perlref
這是將匿名散列引用分配給標量。
這是一個參考(就像一個指針,但不是真的)。
這是一個標量,它保存對另一個標量,數組或散列的引用。關於這個問題
的Perldoc頁:http://perldoc.perl.org/perlreftut.html
見[perlref](http://perldoc.perl.org/perlref.html),[perldata](http://perldoc.perl.org/perldata。 html),[perlreftut](http://perldoc.perl.org/perlreftut.html)。 – pilcrow 2013-05-10 19:45:55
[Perl語法與參考相關]的可能重複(http://stackoverflow.com/questions/15345834/perl-syntax-in-relation-to-references) – 2013-05-12 17:36:22