You are here iC Home > Perl > Data Encoding > UTF to ISO

Perl

2.6.1 UTF to ISO

04.12.2008
2.6 Data Encoding [  up  ] - [ a - z ] - [ search PC ] - [ top ] 2.6.2 ISO to UTF

Download → files/toiso pl.txt
#!/usr/bin/perl -w
$| = 1;
use strict;

use Unicode::String qw(latin1 utf8);

my $foo = $ARGV[0] || '';

$foo = &toISO($foo);

print "-> $ARGV[0]\n";
print "<- $foo\n";

sub toISO($) {
        my $text = $_[0];
        # if this host was UTF-8 encoded:
        my $text_iso  = (utf8($text))->latin1;
        my $text_utf8 = (latin1($text_iso))->utf8; # reverse check

        if ($text ne $text_utf8) {
                # print STDERR "Unequal reverse check! It seems your input data \"$text\" is ",
                #        "ISO encoded already, so you don't need the latin1 encoding stuff here!\n";
                # I'm going to fix this
                $text_iso = $text;
        }
        $text_iso;
}



See also:
To utf
Web encoding decoding


Advanced search tips
2.6 Data Encoding [  up  ] - [ top ] 2.6.2 ISO to UTF



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi