ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/utils/regiontree
Revision: 1.1
Committed: Wed Jan 24 14:50:16 2007 UTC (17 years, 4 months ago) by elmex
Branch: MAIN
Log Message:
added script to print a region tree

File Contents

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