Hugeusrealus has asked for the wisdom of the Perl Monks concerning the following question:

Wisest of monks, Here again I am faced with an undoubtedly easy coding problem that I am struggling helplessly with, so I ask; I need to convert 1 of my variables from EUC to Shift-JIS so it will all appear as readable characters in peoples e-mail clients. It is that simple but I can稚 seem to find a straightforward answer. Here is an example of what I am using.
#!/usr/bin/perl -w use strict; use warnings; use CGI; use Jcode; use DBI; use HTML::Template; use MIME::Base64; require 'jcode.pl'; $| = 1; #unbuffer output $CGI::DISABLE_UPLOADS = 1; # no file uploads - DoS Attack countermeas +ure print "Content-Type: text/html\n\n" ; my $error; # Get the input from the user my $query = new CGI; # set up the database connection my $db = 'test_db'; my $dbhost = '127.0.0.1'; my $dbuser = 'zyxuser'; my $dbpass = 'xyzpass'; my $dbh = DBI->connect("dbi:mysql:$db:$dbhost",$dbuser,$dbpass) + or print qq("COULD NOT INITIALIZE DATABASE $DBI::errstr"); ############################# Start Programing define variables####### +########## my $camp_id = $query->param('camp_id'); my $user_id = $query->param('user_id'); my $email = $query->param('email'); my $name = $query->param('name'); my $zip1 = $query->param('zip1'); my $zip2 = $query->param('zip2'); my $prefect = $query->param('prefect'); my $city = $query->param('city'); my $street = $query->param('street'); my $ADSL = $query->param('ADSL'); my $intrest1 = $query->param('intrest1'); my $intrest2 = $query->param('intrest2'); my $intrest3 = $query->param('intrest3'); my $do_this = $query->param('do_this'); my $do_that = $query->param('do_that'); my $zip = "$zip1-$zip2"; my $intrest = "$intrest1-$intrest2-$intrest3"; my $reply_to = "info\@myhouse.co.jp"; my $subject = q(=?iso-2022-jp A JIS ENCODED subje +ct THAT WORKS==?=);; my $body =q( お世話になっております。 後ほどスタッフよりご連絡させていただきます。); ######## Edited out template part for brevity######### my $mail = qq(To: $email Reply-to: $reply_to From: $reply_to Subject: $subject Content-type: text/plain; charset="ISO-2022-JP" Content-transfer-encoding: 7bit Status: $name 様 $body ); open(MAIL,"| sendmail -t") || die "can't pipe to sendmail"; print MAIL $mail; close(MAIL);
The DB is required to have the text put in EUC. When I try to send the mail with everything EUC clients say it is mojibaki (Japanese unreadable characters). Hence after checking I should be sending the mail in Shift-JIS. The script is simple get text from a form and put the out put to a html template and then send the user a thank you mail with their name in the body and some Japanese text. please bring me enlitenment Hugeus

Readmore tags added by davido per consideration.

Replies are listed 'Best First'.
Re: Changing text Encoding EUC Shift-Jis
by PodMaster (Abbot) on Jan 24, 2005 at 08:34 UTC
    Here again I am faced with an undoubtedly easy coding problem that I am struggling helplessly with
    Undoubtedly easy? Maybe if you've read perluniintro and perlunicode. I suspect you're missing an appropriate binmode call and/or use utf8/bytes.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      In a effort to make the myself feel like less of a "retardo" and more like some one who did there research for 3 days before asking this question. and maybe get back a couple points.
      my $name_coded = &jcode::sjis($name);
      then changed the the value in the mail out portion to $name_coded fixed my problem. Thanx E./ Sorry I am not a great perl programer just the asker of semi -intelligent questions. ps I got this anwser from a japanese text book.
        ... ps I got this anwser from a japanese text book.
        Well, I saw use Jcode; and made the assumption(d'oh) that you've actually used it. If you've got perl 5.7 and up, you should definetly just use Encode (as reccomended in perlunicode) and use
        use Encode qw/ encode decode /; my $name_coded = encode("7bit-jis", decode("euc-jp",$name));
        That is assuming that $name is encoded in euc-jp, and 7bit-jis is what you actually want (as opposed to shiftjis, in which case you just put in shiftjis ).

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.