很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center .
8年前关闭。
编辑:
如何将@myarr 插入 $menu(见下文)
my @myarr = (
[ "itemone", "itemoneb", "itemonec" ],
[ "itemtwo", "itemtwob", "itemtwoc" ],
[ "itemthree", "itemthewwb", "itemthreec" ],
[ "itemfour", "itemfourb", "itemfourc" ]
);
$menu = [
"List",
["itemone", \&ds2],
["itemtwo", \&ds2],
["itemthree", \&ds2],
["itemfour", \&ds2],
[ "Do Something (second)", \&ds2 ]
];
最佳答案
这取决于您究竟想做什么。
您可以直接推送数组:
push (@$menu, @myarr);
#results in:
[
"List",
["itemone", \&ds2],
["itemtwo", \&ds2],
["itemthree", \&ds2],
["itemfour", \&ds2],
[ "Do Something (second)", \&ds2 ],
[ "itemone", "itemoneb", "itemonec" ],
[ "itemtwo", "itemtwob", "itemtwoc" ],
[ "itemthree", "itemthewwb", "itemthreec" ],
[ "itemfour", "itemfourb", "itemfourc" ]
];
这导致
myarr
元素被推送到 menu
,或推送引用:push (@$menu, \@myarr);
#results in:
[
"List",
["itemone", \&ds2],
["itemtwo", \&ds2],
["itemthree", \&ds2],
["itemfour", \&ds2],
[ "Do Something (second)", \&ds2 ],
[
[ "itemone", "itemoneb", "itemonec" ],
[ "itemtwo", "itemtwob", "itemtwoc" ],
[ "itemthree", "itemthewwb", "itemthreec" ],
[ "itemfour", "itemfourb", "itemfourc" ],
],
];
这实际上插入了数组(嵌套数组)。
关于arrays - 将数组插入数组 perl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13133587/