I think this does more or less what you want:

#!/usr/bin/perl -w

use strict;
use Template;

my $template = Template->new()
    || die $Template::ERROR, "\n";

my %tree;
while (my $line = <DATA>)
{
    my ($item, $parent) = split /\s+/, $line;
    push @{$tree{$parent}}, $item;
}

my $ttext=<<'XXX';
[% TAGS (* *) %]
(* BLOCK display -*)
<UL depth="(* depth *)">
(* FOREACH child=Tree.$key -*)
  <LI>(* child *)  (*  *)
(*  INCLUDE display  key=child depth=depth+1 | indent(depth)
      IF Tree.$child *)
(* END -*)
</UL>
(* END *)

(* INCLUDE display key='root' depth = 1 *)

XXX

$template->process(\$ttext,
                   {Tree         => \%tree },
                   ) or die $template->error();

__DATA__
a       root  
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