加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 21:53:45 所属栏目:大数据 来源:网络整理
导读:我是perl的新手.所以这个问题可能听起来很幼稚. 我有两个以下功能 #This function will return the reference of the arraysub getFruits1{ my @fruits = ('apple','orange','grape'); return @fruits;} 但在以下情况下? #How it returns?sub getFruits2{
我是perl的新手.所以这个问题可能听起来很幼稚.

我有两个以下功能

#This function will return the reference of the array
sub getFruits1
{
    my @fruits = ('apple','orange','grape');
    return @fruits;
}

但在以下情况下?

#How it returns?
sub getFruits2
{
    my @fruits = ('apple','grape');
    return @fruits;
}

getFruits2会返回一个引用,是否会创建该数组的新副本?

解决方法

getFruits2子例程返回一个列表,可以将其分配给这样的新数组
my @newfruits = getFruits2();

是的,它将生成数组中的数据副本

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读