I have been asked to come up with a multilingual feedback button for my company. The issue is that when two bit foriegn characters come throught the script it gets changed to high ASCII and there fore unreadable. I need to have a filter on it to change the characters back for localization.

Here is the code I have to work with.

#!/usr/local/dthink/perl/bin/perl ###################################################################### +######### # ddt.cgi - a script to take a form and mail its contents to +someone # # copyright digitalthink, inc. # ###################################################################### +######### # RCS$Id$ # tabstop = 3 ###################################################################### +######### # setup require 5.003; use CGI qw(:all); use strict; package main; # unbuffer my output $| = 1; $main::cgi = new CGI; #if ($main::cgi->request_method() ne "POST") #{ # Error("This is an invalid request."); #} #else { SendTheMail(); SendSuccessPage(); } exit (0); ###################################################################### +######### # subroutines ###################################################################### +######### # void SendSuccessPage (Scalar $message) # sends the success page back to the browser # uses $main::cgi sub SendSuccessPage { my ($location) = '/Templates/beta/beta_bugthanks.html'; print "Location: ${Globals::baseurl}$location\n\n"; exit (0); } # void SendTheMail (void) # sends the mail message # uses $main::cgi sub SendTheMail { my ($to) = '######@digitalthink.com'; ###removed names for privac +y my ($cc) = '######@digitalthink.com'; my ($from) = '######@digitalthink.com'; my ($subject) = 'defect submit'; my ($type) = $main::cgi->param('Type'); my ($bugsubject) = $main::cgi->param('BugSubject'); my ($course) = $main::cgi->param('Course'); my ($hardware) = $main::cgi->param('Hardware'); my ($operatingsystem) = $main::cgi->param('OS'); my ($browser) = $main::cgi->param('Browser'); my ($modulenumber) = $main::cgi->param('ModuleNumber'); my ($lessonnumber) = $main::cgi->param('LessonNumber'); my ($description) = $main::cgi->param('Description'); my ($name) = $main::cgi->param('Name'); my ($email) = $main::cgi->param('EMail'); my ($priority) = $main::cgi->param('Priority'); my ($project) = $main::cgi->param('Project'); my ($subsystem) = $main::cgi->param('Subsystem'); my ($stage) = $main::cgi->param('Stage'); open (MAIL, "|/usr/lib/sendmail -t") || Error("Unable to run mail program"); print MAIL <<EOMH; To: $to CC: $cc From: $from Subject: $subject Class: $type Project: $project Priority: $priority BriefDescription: $bugsubject Subsystem: $subsystem SubsystemName: $subsystem Stage: $stage Feature: $course FeatureName: $course Hardware: $hardware OS: $operatingsystem Browser: $browser module_number: $modulenumber lesson_number: $lessonnumber {Description: $description Submitted by: $name Submitter's email: $email } EOMH close (MAIL); } # void CheckForRequiredData (void) # check to make sure we have at least the two email addresses # uses $main::cgi sub CheckForRequiredData { unless ($main::cgi->param('Type')) { Error("Don't mess with my form!!!!\n"); } } # void Error (Scalar $message) # sends an error page to the browser # uses $main::cgi sub Error { my ($errorMessage) = @_; print $main::cgi->header(-"type" => 'text/html'); print $main::cgi->start_html( -"title" => 'Sorry! There was an error', -"text" => '#000000', -"bgcolor" => '#ffffff', ); print $main::cgi->strong("Error"); print "<p>$errorMessage<p>"; print $main::cgi->end_html; exit (1); }

Here is the psuedo code that I have come up with. A filter to determin if the bug comming in is multilingual. Then at the end changing the high ASSCII characters back into UTF-8. However, After researching Unicode I don't know if the unicode assembler below is the right thing to use.

#!/usr/local/bin/perl -w ################################################################ #Code is to filter and change High Ascii to UTF-8 compliant ccs# # Written By. tdadis@digitalthink.com # ################################################################ require 5.003; use CGI qw(:all); use strict; package main; $OUTPUT_AUTOFLUSH = 1; $main::cgi = new CGI; ##################################################################### +# #if the FeatureName: $Course = to multilingual course code do this +# ##################################################################### +# if (#######) { SendTheMulitibitMail(); SendSuccessPage(); Multilingual(); } else { SendTheMail(); SendSuccessPage(); } ###################################################################### +# # This Sub to change multibit ascii characters to UTF-8 compliant +# ###################################################################### +# sub Multilingual { local ($_) =@_; return $_ < 0x80 ? chr($_): $_ < 0x800 ? chr($_>>6&0x3f|0x +C0) . chr($_&0x80) : chr($_>>12&0x0F|0xE0) .chr($_>>6&0x3F|0x80) .chr +($_&0x3F|0x80); } s/<U([0-9A-F]{4})>/&utf8(hex($1))/gei; ###################################################################### +####### #The sub SendTheMultibitMail is changed only in the to mail bucket + # ###################################################################### +####### sub SendTheMultibitMail { my ($to) = '####somemailbucket####'; my ($cc) = '#####@digitalthink.com'; my ($from) = '####@digitalthink.com'; my ($subject) = 'defect submit'; my ($type) = $main::cgi->param('Type'); my ($bugsubject) = $main::cgi->param('BugSubject'); my ($course) = $main::cgi->param('Course'); my ($hardware) = $main::cgi->param('Hardware'); my ($operatingsystem) = $main::cgi->param('OS'); my ($browser) = $main::cgi->param('Browser'); my ($modulenumber) = $main::cgi->param('ModuleNumber'); my ($lessonnumber) = $main::cgi->param('LessonNumber'); my ($description) = $main::cgi->param('Description'); my ($name) = $main::cgi->param('Name'); my ($email) = $main::cgi->param('EMail'); my ($priority) = $main::cgi->param('Priority'); my ($project) = $main::cgi->param('Project'); my ($subsystem) = $main::cgi->param('Subsystem'); my ($stage) = $main::cgi->param('Stage'); open (MAIL, "|/usr/lib/sendmail -t") || Error("Unable to run mail program"); print MAIL <<EOMH; To: $to CC: $cc From: $from Subject: $subject Class: $type Project: $project Priority: $priority BriefDescription: $bugsubject Subsystem: $subsystem SubsystemName: $subsystem Stage: $stage Feature: $course FeatureName: $course Hardware: $hardware OS: $operatingsystem Browser: $browser module_number: $modulenumber lesson_number: $lessonnumber {Description: $description Submitted by: $name Submitter's email: $email } EOMH close (MAIL); }

I would apreciate any help I can get. I am stumped. Ever humble Newbie Satanya.


In reply to Confusion abounds about UTF-8 Please help by Satanya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.