in reply to UTF8 to Latin-1 and back using Perl-6

I am not enough of an expert in this but the UC/CU modifiers are (already!) deprecated and will be removed from future versions. I think they are not even in 5.7. The 2 preferred ways of converting are using Unicode::String or using Text::Iconv if your system supports the iconv function (try iconv --list to check out if it's on your system and for a list of supported character sets, I believe UTF8 or UTF-8 and LATIN1 or ISO_8859-1) or ISO_8859-1:1987 are the codes you want to use.

I also found an other way to do utf8->latin1 transcoding, which does not require any additional module. But first a warning:

Warning: Calgo-Cult programming follows.

Here is the utf8 to latin1 conversion used in XML::TiePYX. I don't pretend I really know what's going on there.

sub encode { my ($text)=@_; $text=~s/\x0a/\\n/g; $text=~s{([\xc0-\xc3])(.)}{ my $hi = ord($1); my $lo = ord($2); chr((($hi & 0x03) <<6) | ($lo & 0x3F)) }ge; return $text; }