Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl Encoding/Decoding Doubt: From a Novice

by Khen1950fx (Canon)
on Jul 04, 2013 at 14:01 UTC ( #1042458=note: print w/ replies, xml ) Need Help??


in reply to Perl Encoding/Decoding Doubt: From a Novice

Since you're are reading a Word file, you want to use the reverse: encode_utf8 and encode instead of decode. I use binmode to print the set of characters 'as is'.

#!/usr/bin/perl -l use strict; use warnings; use Encode qw(encode encode_utf8); $| = 1; my $str = "irs"; $str = encode_utf8($str); print $str; my $str1 = "irs—"; $str1 = encode('UTF-8', $str1); binmode STDOUT, ":encoding(UTF-8)"; print $str1;


Comment on Re: Perl Encoding/Decoding Doubt: From a Novice
Download Code
Re^2: Perl Encoding/Decoding Doubt: From a Novice
by ppremkumar (Novice) on Jul 04, 2013 at 15:34 UTC

    I tried the coding you provided, but I get the below output.

    Çirçös Çirçös—

    If it helps, I am using Windows: Windows 7 Professional 32-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.130318-1533)

      My bad. I was thinking of Linux. How about this:
      #!/usr/bin/perl -l use warnings; use strict; use Encode qw(encode_utf8); $| = 1; binmode STDIN, ":encoding(UTF-8)"; my $str = 'irs'; $str = encode_utf8($str); print "$str"; my $str1 = 'irs—'; $str1 = encode_utf8($str1); binmode STDOUT, ":encoding(UTF-8)"; print "$str1";
      I'm on Fedora, so I'm flying blind. Does that help?

        It still doesn't work.

        I tried the below coding as well, but to no avail.

        use open ':std' => ':locale'; # Error: Cannot figure out an encoding to use

        Windows doesn't seem to accept the above coding as well.

        Now, should I go about changing those characters to HTML entities in Microsoft Word itself and then try doing the conversion, in which case there shouldn't be any problem.

        But I am still hopeful there is another way

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1042458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-07-04 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls