相关疑难解决方法(0)

Perl:函数返回引用还是复制?

我是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返回引用并创建该数组的新副本?

perl function return-type

7
推荐指数
1
解决办法
2209
查看次数

标签 统计

function ×1

perl ×1

return-type ×1