in reply to ASCII to UTF-8
-----------------------use strict ; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use HTML::Template; use Data::Dumper; use Unicode::String; my $q = new CGI; print $q->header(); #my $template = "wsillafu.tmpl"; my $template = "bbc/lemma/wsillafu.tmpl"; my $tmpl = new HTML::Template( filename => $template, associate => $ +q ); my $errorchecker = "0";my $memoryoverloadchecker = "0"; my $memorych +ecker = "0"; my $dictionarychecker = "0";my $otherchecker = "0";my $memoryfinder += "0"; if ($q->param()) { (my $spellingcheck, my $error) = lookup($q->param("brawddeg +")); #print Dumper( $spellingcheck ); #print "error = $error<br>"; $tmpl->param( spellingcheck => $spellingcheck ); if($error == 1){$errorchecker = "1"; $memoryfinder = "1";} if($error == -1){$memoryoverloadchecker = "1"; $memoryfinder + = "1";} if($error == -2){$memorychecker = "1"; $memoryfinder = "1";} if($error == -3){$dictionarychecker = "1"; $memoryfinder = "1"; +} if($error == -4){$otherchecker = "1"; $memoryfinder = "1";} } print $tmpl->output; if( $dictionarychecker eq "1" ) { print "<br><br>Nid yw\'r geiriadur ar-lein ar gael. E-bostiw +ch meistr y wefan am gymorth \n"; } if( $otherchecker eq "1" ) { print "<br><br>Mae gwall yn y gwirydd. E-bostwich meistr y w +efan am gymorth \n"; } if( $memoryoverloadchecker eq "1" ) { print "<br><br>Roedd mwy na 10 gwall yn y testun. Dim ond y +10 gwall cyntaf sydd wedi ei cywiro.<br> Cywirwch rhain cyn cario ymlaen i gywiro.\n"; } if( $memorychecker eq "1" ) { print "<br><br>Mae'r gwirydd wedi rhedeg allan o gof. E-bost +iwch meistr y wefan am gymorth.\n"; } if( $errorchecker eq "1" ) { print "<br><br><font color=\"red\"><b>Mae rhai gwallau yng ng +horff y testun.</b></font><br> Dewiswch air â gynhigir yn y blwch tynnu i lawr i bob gair sy +dd wedi ei sillafu'n anghywir. <br>Yna gwagswch y botwm gwirio isod i gael eich testun wedi +ei wirio.<br>\n"; print "<form name=\"ArgraffyddTestun\" method=\"POST\" Action +=\"wsillafudangos.pl\">\n"; print "<input type=\"Submit\" name=\"Gwirio\" value=\"Gwirio\ +"></form>\n"; } if( $memoryfinder eq "0" ) {print "<br><br><b>Nid oedd gwall yn y + frawddeg</b>\n";} use lemma; sub lookup() { $_ = shift(@_); #print "Paramater: $_ \n"; #my $br = ""; #$br->String::latin1( $_ ); #print "Latin1 $br \n"; (my $errors, my $str) = lemma::GetCysillSpellingErrors($_, 10); #print "$str\n"; my @fields = split ("(<awgrymiadau>[^<]*</awgrymiadau>)", $str); #print Dumper(@fields); my $error = ( @fields > 1); my @spellingcheck = (); for(my $i=0; $i<@fields; $i+=2) { my %pair; if($i+1 == @fields) { %pair = (text=> @fields[$i]); } else { @fields[$i+1] =~ s/<[^>]*>//g; my @SuggestionList = split /,/, @fields[$i+1]; #print "SuggestionList = ",Dumper(@SuggestionList); my @suggestions = (); my $suggestion; foreach $suggestion (@SuggestionList) { my %hash = (suggestion=> $suggestion); push @suggestions, \%hash; } %pair = (text=> @fields[$i], thesuggestions=>\@suggestions) +; } push @spellingcheck, \%pair; } #print Dumper(@spellingcheck); return (\@spellingcheck, $errors) ; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: ASCII to UTF-8
by rattusillegitimus (Friar) on Jul 27, 2002 at 05:02 UTC |