Hi, Team

I am at loss in terms of understanding the encoding process required in Perl with regard to writing results to the command prompt or to a file.

In the below code, the first portion outputs just fine. In portion 2, however, when I added an em dash or the set of characters "ĀǎỠĨǒAder," the output is junk. (Yes, I want to print out ĀǎỠĨǒAder as is.)

use warnings; use strict; use Encode qw(encode decode); # portion 1 my $str = 'Çirçös'; $str = decode('utf-8', $str); print "$str\n"; # portion 2 my $str1 = 'Çirçös—'; # HTML entity (decimal) for em dash: — $str1 = decode('utf-8', $str1); print "$str1\n"; # output from my Eclipse editor # Çirçös # Çirçös— # Wide character in print at D:/EPIC_workspace/PERL/Bibliography/test. +pl line 10.

Please help me understand what I am doing wrong.

What I am really trying to do is read a Microsoft Word file that has special characters and store that data into a text file.

Thanks,

Prem

UPDATE: I have found a solution to my problem: http://www.lemoda.net/perl/win32-ole-utf8/cp-utf8-ole.html

I had to set the Win32 component to CP_UTF8 and set the code page of Win32::OLE to CP_UTF8.

Now, even if my Microsoft Word files have special characters such as "Aderñŋšžľŀīửừứ," I could read each line of the Word file and save it in a text file without loss of characters. I thank each of you for your help and time. Greatly appreciated

# Get the constant. use Win32::OLE 'CP_UTF8'; # Set the code page of Win32::OLE. $Win32::OLE::CP = CP_UTF8;

In reply to Perl Encoding/Decoding Doubt: From a Novice by ppremkumar

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.