Hello,

I am working on an application that may receive HTML and XML data in several encodings, notably ISO-88591-1 and UTF-8. In my test scripts I would like to encode the test data in different encodings, and by setting the appropriate HTTP headers, I want to make sure that my application won't choke on them.

I understand that Perl uses utf8 (lax UTF-8) and all my source code is encoded in UTF-8. I read the Encode perldoc and tried this:
#!/usr/bin/perl use strict; use warnings; use Encode; my $perl_str = "αινσϊρό"; print "IN UTF:$perl_str\n"; my $iso_str = encode("iso-8859-1", $perl_str); print "IN ISO:$iso_str\n"; my $utf_str = decode("iso-8859-1", $iso_str); print "BACK IN UTF:$utf_str\n";


To my surprise the complete output was readable on my shell which should have printed funny characters for the LATIN1 prints (because my shell is configured for UTF-8). I am guessing that Perl translated back to utf8 automagically but would like to corroborate with more knowledgeable monks. Also, if anyone knows and could kindly point to a module that performs these types of tests, would really appreciate it.

Thanks beforehand,
Alejandro Imass

In reply to How to test different encoding by ait

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.