[Templates] Calling subroutine
Tim Dolezal
tdolezal@ces-inc.cc
Thu, 16 Jan 2003 13:51:21 -0800
Can I do this is a template?
#!/usr/bin/perl -w
use strict;
my %tree;
while (my $line = <DATA>)
{
my ($item, $parent) = split /\s+/, $line;
push @{$tree{$parent}}, $item;
}
print_node("", "");
sub print_node
{
my ($key, $indent) = @_;
return unless exists $tree{$key};
my @children = @{$tree{$key}};
for (my $i = 0; $i < @children; ++$i)
{
my $child = $children[$i];
print "$indent| \n";
print "$indent\\-$child\n";
my $new_indent = $indent . (($i == @children - 1)? " ": "| ");
print_node($child, $new_indent);
}
}
__DATA__
a
b a
c b
d c
e c
f a
g d
h f
i f
j i
k i
l k
m a