Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shift jis decoding/encoding in perl

When I try decode a shift-jis encoded string and encode it back, some of the characters get garbled: I have following code:

use Encode qw(decode encode);
$val=;
print "\nbefore decoding: $val";
my $ustr = Encode::decode("shiftjis",$val);
print "\nafter decoding: $ustr";
print "\nbefore encoding: $ustr";
$val = Encode::encode("shiftjis",$ustr);
print "\nafter encoding: $val";

when I use a string : helloソworld in input it gets properly decoded and encoded back,i.e. before decoding and after encoding prints in above code print the same value. But when I tried another string like : ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ

The end output got garbled.

Is it a perl library specific problem or it is a general shift jis mapping problem? Is there any solution for it?

like image 319
Sushant Avatar asked Apr 22 '26 16:04

Sushant


1 Answers

You should simply replace the shiftjis with cp932.

http://en.wikipedia.org/wiki/Code_page_932

like image 165
yibe Avatar answered Apr 24 '26 06:04

yibe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!