Cookbook / Encode

Jan 22, 2007 17:24


Полезный модуль для перекодировки строк:

#!/usr/bin/perl

use strict;
use Encode;

my $string = "Русский текст";
print "Original string (CP1251):$string\n";

# trnslate into internal format
my $str_i = decode("cp1251", $string);

# recode to other charsets
my $str_o_utf8 = encode("utf8", $str_i);
print "UTF8:$str_o_utf8\n";

my $str_o_866 = encode("cp866", $str_i);
print "CP866:$str_o_866\n";

my $str_o_koi = encode("koi8-r", $str_i);
print "KOI8-R:$str_o_koi\n";

perl, km, cookbook

Previous post Next post
Up