>>>>> "Wayne" == Wayne Pascoe <[EMAIL PROTECTED]> writes:
Wayne> Is there any way to do this in a template using Template::Toolkit ? If there
Wayne> is no way of doing this in Template::Toolkit, what is the right way of
Wayne> building the hash then ? The HTML that I want to end with is
Wayne> <li><a href="URL">CLIENT</a> - YNUMBER - DATE</li>
Wayne> <li><a href="URL">CLIENT</a> - YNUMBER - DATE</li>
Wayne> <li><a href="URL">CLIENT</a> - YNUMBER - DATE</li>
Wayne> Where each of those lines has one of the URL's, CLIENT's, YNUMBERS and
Wayne> DATE's from my database.
This example might be useful... I just hacked it up for Perlmonks. It
uses hash(ref)s of hash(ref)s of array(ref)s. It also shows how to put
a quick-and-dirty template inside a Perl program, which I had to spend
about 15 minutes one day to figure out, so you get that for free. :-)
#!/usr/bin/perl
my %d;
while (<DATA>) {
my ($file, $line, $comment) = /^([^:]+):(\d+)\s+(.*)/
or warn("unknown line, skipping: $_"), next;
push @{$d{$file}{$line}}, $comment;
}
use Template;
Template->new->process(\<<'EOT', { d => \%d, env => \%ENV })
[%# USE Dumper; Dumper.dump(d); -%]
[%-
FOREACH filek = d.keys.sort;
filev = d.$filek;
FOREACH linek = filev.keys.nsort;
linev = filev.$linek;
"<dt>$filek</dt> <dd><b>line $linek</b>\n";
FOREACH comment = linev;
" <ul>\n" IF loop.first;
" <li>"; comment | html; "</li>\n";
" </ul>\n" IF loop.last;
END;
END;
"</dd>\n";
END;
-%]
EOT
or die Template->error;
__END__
comment_tmpl.tt2:1 This would be more readable if I turned on Template's
space-stripping options.
comment_reader.pl:31 More informative error message would probably be good.
comment_reader.pl:71 Need a better explanation of data structure.
annotate.el:1 Should properly be in a mode...
annotate.el:11 Should be configurable variable
annotate.el:13 Formatting should be configurable in variable
annotate.el:11 Should automatically make "annotations" visible if it isn't already
annotate.el:21 Control-c keys are supposed to be for mode-specifics...
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!