#!/usr/bin/perl
use strict;
my $new=0;
my $parent;
my $hostname;
my %topology;
while(<>){
if(m/define host/ .. /}/){
if(!$new and (($hostname) = m/host_name\s+(\S+)/)){
$new=1;
next;
}
if(($parent) = m/parents\s+(\S+)/){
$topology{$parent} .= " $hostname" unless($topology{$parent} =~ m/$hostname/);
$new=0;
}
}
}
foreach (keys %topology){
print "$_:\n";
foreach my $host (split ' ',$topology{$_}){
print "\t$host\n";
}
}
|