+-----------------------------------------------------------------+
| |
| Decoded Text |
| |
| |
| +--------------------+ downgrade +--------------------+ |
| | Internally encoded | --------------> | Internally encoded | |
| | as UTF-8 | | as iso-8859-1 | |
| | (is_utf8 = 1) | <-------------- | (is_utf8 = 0) | |
| +--------------------+ upgrade +--------------------+ |
| |
+-----------------------------------------------------------------+
| ^
| |
encode | | decode
| |
v |
+-----------------------------------------------------------------+
| |
| Bytes or |
| Encoded Text |
| |
| |
| +--------------------+ downgrade +--------------------+ |
| | Internally encoded | --------------> | Internally encoded | |
| | as UTF-8 | | as iso-8859-1 | |
| | (is_utf8 = 1) | <-------------- | (is_utf8 = 0) | |
| +--------------------+ upgrade +--------------------+ |
| |
+-----------------------------------------------------------------+
####
use Encode qw(is_utf8 encode decode);
binmode STDOUT,':encoding(iso-8859-1)';
my $str = "This's a \x{201c}test\x{201d}"; # This is a "decoded" str.
print "$str\n"; # Encoded by :encoding
##
##
use Encode qw(is_utf8 encode decode);
my $str = "This's a \x{201c}test\x{201d}"; # This is a "decoded" str.
print encode('iso-8859-1', "$str\n");