Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: What encoding am I (probably) using?

by ysth (Canon)
on May 13, 2005 at 13:25 UTC ( [id://456727]=note: print w/replies, xml ) Need Help??


in reply to What encoding am I (probably) using?

UPDATE: Thanks monks, Encode::Guess looks good. I'm going to go try it out.
A quick read of the doc does not seem to indicate this would guess well among 1-byte encodings.

Ah, yes; it says:

CAVEATS
Because of the algorithm used, ISO-8859 series and other single-byte encodings do not work well unless either one of ISO-8859 is the only one suspect (besides ascii and utf8).
  • Comment on Re: What encoding am I (probably) using?

Replies are listed 'Best First'.
Re^2: What encoding am I (probably) using?
by tphyahoo (Vicar) on May 13, 2005 at 13:58 UTC
    Yes, unfortunately my experience so far seems to bear this out. After mucking around for a while I came up with the following code, which doesn't really solve anything but perhaps may inspire one wiser than me to share a better solution...
    use warnings; use strict; use PPM::Repositories; use Encode::Guess; # OS Call on German WinXP my $result = `ping -n 1 jenda.krinicky.cz ` . "\n"; my $encoding; #works, as expected. print "cp437:\n"; $encoding = guess_encoding_cp437($result); if ( ref( $encoding ) ) { test_ping_result($result, $encoding->name); } else { print "Couldn't guess encoding.\n"; } #doesn't work print "default:\n"; $encoding = guess_encoding_default($result); if ( ref( $encoding ) ) { test_ping_result($result, $encoding->name); } else { print "Couldn't guess encoding.\n"; } #doesn't work. print "kitchen sink:\n"; $encoding = guess_encoding_default($result); if ( ref( $encoding ) ) { test_ping_result($result, $encoding->name); } else { print "Couldn't guess encoding.\n"; } sub test_ping_result { my $result = shift; my $encoding = shift; Encode::from_to($result,"$encoding",'iso-8859-1'); print "encoding: $encoding\n"; print "result: $result\n"; if ($result =~ /Überprüfen/) { # should match but fails because of + german characters print "Ping timed out \n"; } else { #good repository. print "Ping ok \n"; } } sub guess_encoding_cp437 { my $data = shift; my $enc = guess_encoding($data, ('cp437')); return $enc; } sub guess_encoding_default { my $data = shift; my $enc = guess_encoding($data); return $enc; } sub guess_encoding_kitchen_sink { my $data = shift; my $enc = guess_encoding($data, ( Encode->encodings() ) ); return $enc; } __END__ Outputs: cp437: encoding: cp437 result: Ping-Anforderung konnte Host "jenda.krinicky.cz" nicht finden. + Überprüfen Sie den Namen, und versuchen Sie es erneut. Ping timed out default: Couldn't guess encoding. kitchen sink: Couldn't guess encoding.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found