http://www.perlmonks.org?node_id=763044
Swalif's user image
User since: May 09, 2009 at 15:00 UTC (9 years ago)
Last here: May 07, 2018 at 09:38 UTC (6 weeks ago)
Experience: 354
Level: Scribe (6)
Writeups: 38
Location:Saudi Arabia
User's localtime: Jun 19, 2018 at 20:12 UTC
Scratchpad: View
For this user:Search nodes

#!/usr/bin/perl use strict; use CGI; use Encode; use utf8; my $cgi = new CGI; print $cgi->header(-charset=>'UTF-8'), $cgi->start_html ( -title=>'Annotated Translator', -bgcolor=>'lightyellow' ), $cgi->center, $cgi->h1('Annotated Translator V0.1'), $cgi->hr; print "
"; my $input = "ali cat arabic"; my @list = split ' ', $input; my $long; while(my $element=shift(@list)) { print $element; my $test = toArabic($element); if ($test eq "No matches"){ $long.=" $element"; } else{ $long.=" $element"; } } sub toArabic { my $word = shift; $word =~ s/^\s+//; $word =~ s/\s+$//; $word = ucfirst lc $word; my $char = lc substr( $word, 0, 1 ); my $file = "dict/" . $char . "_words.txt"; my %dict; open(my $fh, '<:encoding(UTF-8)', $file) or die "Could not open file '$file' $!"; while (my $row = <$fh>) { chomp $row; my @list = split ':', $row; $dict{$list[0]} = $list1 ;} if (exists $dict{$word}) { my $result = $dict{$word}; return $result; } else { return "No matches"; } } print $long; $cgi->end_html;