好的......这有效......
sub getApSrvs
{
my %apsrv;
my $cluster;
foreach $cluster (getClusters())
{
$apsrv{$cluster} = [split('\s+', `/$cluster/bin/gethosts -t app|sort -u`)];
}
return %apsrv;
}
...现在如何在火腿三明治中打印这样的 $ cluster - > $ hostname
好的,我补充道:
my %apsrv = getApSrvs();
for my $cluster (keys %apsrv) {
print "$cluster -> $apsrv{$cluster}\n";
}
我得到......
qboc22 - > ARRAY(0x9111618)
qboc5 - > ARRAY(0x9111504)
qboc32 - > ARRAY(0x90e20cc)
qboc28 - > ARRAY(0x90e1d28)
qboc30 - > ARRAY(0x90e1f38)
qboc23 - > ARRAY(0x9111540)
qboc27 - > ARRAY(0x911181c)
qboc29 - > ARRAY(0x91115ac)
qbo - > ARRAY(0x90e2294)
答案 0 :(得分:1)
$ apsrv {$ cluster}是对数组的引用,因此如果要打印它的内容,您可以这样做:
my %apsrv = getApSrvs();
for my $cluster (keys %apsrv) {
print "$cluster -> ", join(', ', @$apsrv{$cluster}), "\n";
}
答案 1 :(得分:0)
my %apsrv = getApSrvs();
for my $cluster (keys %apsrv) {
print "$cluster -> $apsrv{$cluster}\n";
}
如果订单很重要,您需要在打印前对键(sort keys %apsrv
)进行排序。