in reply to HTML::Template : generation of links

Looks like you have a lot of bad data in your database:
select distinct site_name from sites order by site_name;
select distinct router from sites where site_name = ?;
select interface from sites where site_name = ? and router = ?
but i don't really see much that we can do about it right now. In the meantime, why don't you try a simpler approach instead. Untested:
use DBI; use HTML::Template; my $dbh = DBI->connent( qw(dbi:mysql:ndb user pass), {RaiseError => 1}, ); my $sites = $dbh->selectall_arrayref(' select distinct site_name as name from sites order by site_name ',{Slice=>{}}); for my $site (@$sites) { $site->{routers} = $dbh->selectall_arrayref(' select distinct router as name from sites where site_name = ? ',{Slice => 1}, $site->{name}); #i removed the router = ? part from here #how do you expect to query a single router if there are multiples? $site->{interfaces} = $dbh->selectall_arrayref(' select interface as name from sites where site_name = ? ',{Slice => 1}, $site->{name}); } my $tmpl = HTML::Template->new(filehandle => \*DATA); $tmpl->param(sites => $sites); print $tmpl->output; __DATA__ <tmpl_loop sites> Name: <tmpl_var name> Routers: <tmpl_loop routers> <tmpl_var name> </tmpl_loop> Interfaces: <tmpl_loop interfaces> <tmpl_var name> </tmpl_loop> </tmpl_loop>
Select dictinct routers from a site, and then trying to only compare one of those to find the correct interface is surely not correct. You really should try to clean up your data first, garbage in --- garbage out. Give this code a shot and see what happens. At the very least, remove the parts of your code that don't matter. Don't worry about table formatting until you have correct data. Simplify. And read the HTML::Template Tutorial if you already haven't.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)