2 days ago, I got an email with below subject

my $subject = "=?GB18030?B?XXXXXXXXXX?=";

then, When I ran the code, I got below error

Unknown encoding "GB18030" at /usr/lib64/perl5/Encode.pm line 174

I searched it. Then I came to know that GB 18030 is a Chinese government standard.

I found below 2 Urls

https://perldoc.perl.org/Encode/CN.html

https://stackoverflow.com/questions/6105316/how-to-convert-from-gbk-encoding-to-utf-8-encoding-in-perl

they talk about Encode::HanExtra

So, Added below line to my code. then, It started working.

use Encode::HanExtra;

So, Here's my UPDATED code. I think it's worth sharing...

#!/usr/bin/perl use strict; use warnings; use Encode qw(encode decode); use Encode::HanExtra; no warnings 'utf8'; my @subject = ("Room Rush \303\242\302\200\302\223 Enjoy 25% off on yo +ur stay. (raw: Room Rush =?utf-8?b?4oCT?= Enjoy 25% off on your stay. +)", "Last Day To Enjoy Extra 15% OFF On Everything For NDB Credit Cards (r +aw: =?utf-8?Q?Last=20Day=20To=20Enjoy=20Extra=2015%=20OFF=20On=20Ever +ything=20For=20NDB=20Credit=20Cards?=)", "Sing Along and Dance with Desmond De Silva at Pegasus Reef Hotel! (ra +w: =?utf-8?Q?Sing=20Along=20and=20Dance=20with=20Desmond=20De=20Silva +=20at=20Pegasus=20Reef=20Hotel=21?=)", "RE: Weekly Report (CommercialLegal) -\303\202\302\240 2 July 2018 to +5 July 2018 (raw: =?UTF-8?Q?RE:_Weekly_Report_=28CommercialLeg?=\t=?U +TF-8?Q?al=29_-=C2=A0_2_July_2018_to_5_July_201?=\t=)", "How are you", "=?GB18030?B?XXXXXXXXXX?="); for my $subj (@subject) { my $subject_decoded = decode("MIME-Header", $subj); print $subject_decoded; print "\n"; }

Have a nice day to all Perl Monks


In reply to Re^6: utf8 in perl by theravadamonk
in thread utf8 in perl by theravadamonk

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.