0

我有一个包含接口名称和目标的数据文件。我想按界面对所有目的地进行分组,以便我可以遍历并存储结果。这是我的输出示例:

eth0,1.1.1.1
eth0,1.1.1.2
eth1,1.1.1.1
eth1,1.1.1.2

如何将唯一的接口值转储到哈希中并构建目标数组?

4

1 回答 1

2
my %ifs;

while ( my $line = <STDIN> ) {
    chomp $line;
    my ( $iface, $destination ) = split /,/, $line;
    push @{ $ifs{ $iface } }, $destination;
}

应该管用。

于 2013-02-11T20:51:09.300 回答