我怎么可以指定在Perl的子程序调用数组引用的结果呢? [英] How can I assign the result of a subroutine call to array references in Perl?

查看:104
本文介绍了我怎么可以指定在Perl的子程序调用数组引用的结果呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能一个数组变量赋值给一个数组引用,而不是标量变量?

Is it possible to assign an array variable to an array reference instead of to scalar variables?

而不是这样的:

($a, $b) = some_sub(\@d, \@e);

我想是这样的:

(@x, @y) = some_sub(\@x1, \@y1);

如果是这样,我怎么能间接引用it.where如在前者的情况下, @ $ XXXX 为我们做。

If so, how can I dereference it.where as in case of former, @$xxxx does for us.

感谢。

推荐答案

您可以做2个步骤(实际上3行):

You can do it in 2 steps (3 lines actually):

my ($x_ref, $y_ref) = some_sub(\@x1, \@y1);
my @x = @{ $x_ref };
my @y = @{ $y_ref };

现在的问题是 - 不会是简单干脆沟直接阵列,并开始使用到处引用

The question is - wouldn't it be simpler to simply ditch the direct arrays, and start using references everywhere?

这篇关于我怎么可以指定在Perl的子程序调用数组引用的结果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆