Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re^2: What encoding am I (probably) using? by tphyahoo
in thread What encoding am I (probably) using? by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found