#!/usr/bin/perl use strict; use warnings; use DBI; use HTML::Template::Compiled; my $tmpl = 'Database.tmpl'; my $template = HTML::Template::Compiled(filename => $tmpl); my ($user,$pass,$db,$host) = ("user","passwort","datenbank","host"); my $dbh = DBI->connect("DBI:mysql:$db:$host",$user,$pass) or die $DBI::errstr; my $stmt = q~SELECT * FROM tabelle~; my $sth = $dbh->prepare($stmt) or die $dbh->errstr(); $sth->execute() or die $dbh->errstr(); my @values; while(my ($col1,$col2) = $sth->fetchrow_array()){ my $class = 0; $class = 1 if $col2 eq 'hallo'; push @values, {VALUE => $col1, CLASS => $class}; } $sth->finish(); $dbh->disconnect(); $template->param(SCHLEIFE => \@values); print $template->output();