Sim*_*eth 0 arrays perl foreach subroutine
#! /usr/local/bin/perl
sub getClusters
{
my @clusters = `/qbo/bin/getclusters|grep -v 'qboc33'`;
chomp(@clusters);
return \@clusters;
}
Run Code Online (Sandbox Code Playgroud)
嗯好吧..我怎么得到这个阵列打印,因为......
foreach $cluster (getClusters())
{ print $cluster."\n"; }
Run Code Online (Sandbox Code Playgroud)
似乎不起作用.谢谢.
您正在返回引用,而不是在任何地方取消引用它.
foreach $cluster (@{getClusters()})
Run Code Online (Sandbox Code Playgroud)
要么
return @clusters;
Run Code Online (Sandbox Code Playgroud)
要么修复它(效果略有不同),第一个是首选(你的数组有点大).
您将使用非引用数组返回有限数量的元素,通常用于多次返回(因此,通常,限制为2或3,已知长度数组).
| 归档时间: |
|
| 查看次数: |
865 次 |
| 最近记录: |