#!/usr/bin/perl use DBI; use CGI qw(:standard *table *Tr); my $dbh = DBI->connect("dbi:Pg:dbname=template1"); my $href = $dbh->selectall_hashref('select id,nombre,apellidos from prueba2', "id"); print start_table, Tr( th( ['Id','Nombre','Apellidos'] ) ), "\n"; for ( sort keys %$href ) { print start_Tr, td( { -bgcolor => 'white' }, $_ ); for my $k ( qw( nombre apellidos ) ) { print td($href->{$_}{$k}); } print end_Tr, "\n"; } print end_table; my $rc = $dbh->disconnect();