Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含接口名称和目标的数据文件。我想按界面对所有目的地进行分组,以便我可以遍历并存储结果。这是我的输出示例:
eth0,1.1.1.1 eth0,1.1.1.2 eth1,1.1.1.1 eth1,1.1.1.2
如何将唯一的接口值转储到哈希中并构建目标数组?
my %ifs; while ( my $line = <STDIN> ) { chomp $line; my ( $iface, $destination ) = split /,/, $line; push @{ $ifs{ $iface } }, $destination; }
应该管用。