#!/usr/bin/perl -w use strict; use warnings; use DBI; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use utf8; use Encode qw(decode decode); binmode(STDOUT, ":encoding(utf8)"); my ($datasource, $user, $passw, $dbh, $sth); my ($id_testo, $indice, $parole, $posizione); my (@row, $field); $datasource = "DBI:mysql:database=Test;host=xxxxxxx;"; $user = "xxxxxxxx"; $passw = ""; $dbh = DBI->connect($datasource, $user, $passw) || die "Error opening db: $DBI::errstr\n"; $dbh->do("SET NAMES 'utf8'"); $sth = $dbh->prepare("SELECT indice, GROUP_CONCAT(parole SEPARATOR ' ') FROM testo GROUP BY indice"); $sth->execute(); print header(-type => "text/html", -charset => "utf-8"), start_html(-encoding => 'utf-8', "My_database"), "\n", h2("ARET 1.1"), "\n"; while (@row = $sth->fetchrow_array) { for $field(@row) { $field =~ s/([à]+)/$1<\/i>/g; # lower --> italic $field =~ s/(\p{Lu}+)/lc($1)/ge; # upper --> lower $field =~ s/-=(.{1,4})/$1<\/sup>/g; # OK } print p(), decode("utf8", "$row[0]\t$row[1]\n"); } $sth->finish(); $dbh->disconnect() || die "fallita disconnessione\n";