Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Can't tell if UTF-8... or just binary...

by zentara (Archbishop)
on Aug 23, 2011 at 18:46 UTC ( #921964=note: print w/replies, xml ) Need Help??


in reply to Can't tell if UTF-8... or just binary...

Maybe Encode::Guess or Encode::Detect can help.
#!/usr/bin/perl use warnings; use strict; use Encode; use Encode::Guess; my $decoder = guess_encoding($content); print "UTF-8" if ref($decoder) eq 'Encode::utf8'; __END__
#!/usr/bin/perl use warnings; use strict; use Encode::Detect::Detector; my $octets = "\x{4f60}\x{597d}\x{4e16}\x{754c}"; my $charset = Encode::Detect::Detector::detect($octets); print "$charset\n"; $octets = "\x82\xb7\x82\xb2\x82\xa2\x82\xcc\x82\xdd\x82\xc2"; $charset = Encode::Detect::Detector::detect($octets); print "$charset\n"; $octets = "\x{805a}\x{5408}\x{6216}\x{8be6}\x{7ec6}"; $charset = Encode::Detect::Detector::detect($octets); print "$charset\n";

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://921964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2021-10-20 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (78 votes). Check out past polls.

    Notices?