| 1 |
elmex |
1.1 |
#!/opt/perl/bin/perl |
| 2 |
|
|
|
| 3 |
root |
1.2 |
# usage: regiontree < maps/regions |
| 4 |
|
|
|
| 5 |
elmex |
1.1 |
my %regions; |
| 6 |
|
|
|
| 7 |
|
|
sub print_rec { |
| 8 |
|
|
my ($reg, $pad) = @_; |
| 9 |
|
|
print ((" " x ($pad * 4))."$reg\n"); |
| 10 |
|
|
for (@{$regions{$reg}->{child}}) { |
| 11 |
|
|
print_rec ($_, $pad + 1); |
| 12 |
|
|
} |
| 13 |
|
|
} |
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
my $curreg = ''; |
| 17 |
|
|
while (<STDIN>) { |
| 18 |
|
|
if (/^region\s*(\S+)\s*$/) { |
| 19 |
|
|
$curreg = $1; |
| 20 |
|
|
$regions{$curreg} = {}; |
| 21 |
|
|
} elsif (/^parent\s*(\S+)\s*$/) { |
| 22 |
|
|
$regions{$1} = {} unless exists $regions{$1}; |
| 23 |
|
|
$regions{$curreg}->{parent} = $1; |
| 24 |
|
|
push @{$regions{$1}->{child}}, $curreg; |
| 25 |
|
|
} |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
for (sort grep { not $regions{$_}->{parent} } keys %regions) { |
| 29 |
|
|
print_rec ($_); |
| 30 |
|
|
} |