好了,所以它很容易地創建一個指向數組的參考...類型團的別名
my @a;
my $b=\@a;
#can now reference the same list of scalars from either @$b or @a
但我怎麼能做到這一點的反向?例如:
my $a=[1..4];
my @b;
#some magic happens here and now @b is an alias for @$a
@b=(6..10);
print "@$a\n"; #should print "6 7 8 9 10"
我認爲這將通過typeglobs發生,但那些只是逃避我。想法?
此外,對散列以及數組做同樣的處理也不錯。
編輯:這似乎是工作,但它的一點點缺憾,因爲它只是複製了匿名數組元素的「別名」,然後再點自己的數組:
my @[email protected]$a;
$a=\@b;
更好的想法?
基本上我偶然發現了什麼,但是你也添加了更多! +1 – mswanberg