#! /usr/bin/perl # Perl v5.8.8 use strict; use Data::Dumper; use Encode; my $string1 = "weight_\x{2639}"; # Valid Unicode my $string2 = "weight_\xc2"; # Valid iso-8859-1 my @words; push(@words,$string1); push(@words,$string2); my $str = join(",", @words); print STDERR "mangled : ".print_chrcodes($str)."\n"; my @words; Encode::_utf8_off($string1); push(@words,$string1); Encode::_utf8_off($string2); push(@words,$string2); my $str = join(",", @words); print STDERR "preserved: ".print_chrcodes($str)."\n"; ############################################################# sub print_chrcodes { my $str = shift; my $ret; foreach my $ascval (unpack("C*", $str)) { $ret .= chr($ascval) if($ascval < 128); $ret .= sprintf ("<#%x>",$ascval) if($ascval >= 128); } return $ret; }