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

Perl

2.6.2 ISO to UTF

21.11.2008
2.6.1 UTF to ISO [  up  ] - [ a - z ] - [ search PC ] - [ top ] 2.7 CGI Programming

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

use Unicode::String qw(latin1 utf8);

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

if (&isISO($foo)) {
	print "Is ISO!\n";
	$foo = (latin1($foo))->utf8;
}
else {
	print "Is UTF\n";
}

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

sub isISO ($) {
	my $text = $_[0];
	my $text_iso  = (utf8($text))->latin1;
	my $text_utf8 = (latin1($text_iso))->utf8; # reverse check
	return $text eq $text_utf8 ? 0 : 1;
}



See also:
Toiso
Web encoding decoding


Advanced search tips
2.6.1 UTF to ISO [  up  ] - [ top ] 2.7 CGI Programming



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi