I would like to know if this functionality can be accomplished from
within a template, i.e. perhaps a block calling itself.

Tim Dolezal

#!/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




_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to