3 回答

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
重要的影響是在聲明變量的同時(shí)初始化變量:
my ($a) = @b; # assigns $a = $b[0]
my $a = @b; # assigns $a = scalar @b (length of @b)
另一個(gè)重要的時(shí)刻是聲明多個(gè)變量。
my ($a,$b,$c); # correct, all variables are lexically scoped now
my $a,$b,$c; # $a is now lexically scoped, but $b and $c are not
如果您使用最后一條語(yǔ)句,則會(huì)給您一個(gè)錯(cuò)誤use strict。

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
簡(jiǎn)短的答案是,括號(hào)在列表的左側(cè)使用時(shí)會(huì)強(qiáng)制列表上下文=。
其他每個(gè)答案都指出了在其中有所作為的特定情況。確實(shí),您應(yīng)該通讀perlfunc,以更好地了解函數(shù)在列表上下文(而不是標(biāo)量上下文)中被調(diào)用時(shí)的行為方式不同。

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊
請(qǐng)查看perdoc perlsub以獲取有關(guān)該my運(yùn)算符的更多信息。這是一個(gè)小摘錄:
概要:
my $foo; # declare $foo lexically local
my (@wid, %get); # declare list of variables local
my $foo = "flurp"; # declare $foo lexical, and init it
my @oof = @bar; # declare @oof lexical, and init it
my $x : Foo = $y; # similar, with an attribute applied
添加回答
舉報(bào)