perl 将字符串分割成二维数组
好吧..这有效......
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->数组(0x9111618)
qboc5->数组(0x9111504)
qboc32->数组(0x90e20cc)
qboc28->数组(0x90e1d28)
qboc30->数组(0x90e1f38)
qboc23->数组(0x9111540)
qboc27->数组(0x911181c)
qboc29->数组(0x91115ac)
qbo->数组(0x90e2294)
Okay .. this works ...
sub getApSrvs
{
my %apsrv;
my $cluster;
foreach $cluster (getClusters())
{
$apsrv{$cluster} = [split('\s+', `/$cluster/bin/gethosts -t app|sort -u`)];
}
return %apsrv;
}
... now how in the ham sandwich do I get this to print like so $cluster --> $hostname
okay I added :
my %apsrv = getApSrvs();
for my $cluster (keys %apsrv) {
print "$cluster -> $apsrv{$cluster}\n";
}
and I get ...
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$apsrv{$cluster} 是对数组的引用,因此如果你想打印它的内容,你可以这样做:
$apsrv{$cluster} is a reference to an array, so if you want to print the contents of it you can do :
如果顺序很重要,您将需要在打印之前对键进行排序(
排序键 %apsrv
)。You will want to sort the keys (
sort keys %apsrv
) before printing if the order is important.