#C:\Perl\bin\perl5.8.8.exe -w use strict; use warnings; use locale; use CGI::Carp qw(fatalsToBrowser); #--------------------------------------------- if (!open(FILEIN,"<chansons.xml")) { die "Pb a l'ouverture du fichier 'chansons.xml'"}; print "Content-type: text/html\n\n"; print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">', "\n"; print "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/></head>\n"; print "<body bgcolor=\"#DDDDDD\"><div align=\"center\"><h3>Index du corpus français</h3>\n"; print "<table border=\"0\" rules=\"rows\" style=\"margin-left:10px;margin-right:10px\">"; print "<tr><th> nb </th><th> Forme </th><th> Occurences </th></tr>\n"; my %index=(); while(my $ligne=<FILEIN>) { if ($ligne=~/<element langue=\"fr\">(.+)<\/element><element langue=\"kb\">(.+)<\/element>/) { my @mots = split(/[ \-'\,\.\!\?]/, $1); foreach my $mot(@mots) { if (! $mot eq "") { $index{$mot}++; } } } } #--------------------------------------------- my @sorted_index = values %index; #tri des nombres d'occurence des mots @sorted_index = sort { $b <=> $a } @sorted_index; #tri numéral décroissant my $existe=0; my $j=0; foreach my $nombre (@sorted_index) { if ($nombre != $existe) { foreach my $mot (keys %index) { if ($index{$mot}==$nombre) { $j++; print "<tr><td> $j </td><td> $mot </td><td> $index{$mot} </td></tr>\n"; } } } $existe=$nombre; } print "</table><h6><a href=\"#ebut\">< Haut de page</a></h6></div></body></html>";