Sam*_*ron 7 perl function return-type
我是perl的新手.所以问题可能听起来很幼稚.
我有两个以下功能
#This function will return the reference of the array
sub getFruits1
{
my @fruits = ('apple', 'orange', 'grape');
return \@fruits;
}
Run Code Online (Sandbox Code Playgroud)
但在以下情况下?
#How it returns?
sub getFruits2
{
my @fruits = ('apple', 'orange', 'grape');
return @fruits;
}
Run Code Online (Sandbox Code Playgroud)
是否会getFruits2返回引用并创建该数组的新副本?
Bor*_*din 12
该getFruits2子程序返回一个列表,可以分配到一个新的数组像这样
my @newfruits = getFruits2();
Run Code Online (Sandbox Code Playgroud)
是的,它将生成数组中的数据副本