I regularly get a batch of HTML containing information about Latin music. I'm having some problems making sure the non-English characters in that data don't get whacked.
Perhaps pertinent, perhaps not, I'm running this on Windows XP with ActivePerl 5.8.
This is a test example of the data:
<?xml version='1.0' encoding='ISO-8859-1'?>
<data>
<title>Más Y Más</title>
<artist>La Unión</artist>
</data>
Here's the code I'm testing:
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;
use Data::Dumper;
undef $/;
open( FH, shift );
my $raw_file = <FH>;
my $xml = XMLin( $raw_file,
forcearray => [],
suppressempty => undef
);
print Dumper ( $xml );
print $xml->{'artist'};
print "\n";
I pass the data file to the script and the output is this:
$VAR1 = {
'artist' => "La Uni\x{f3}n",
'title' => "M\x{e1}s Y M\x{e1}s"
};
La Uni≤n
So, the dumped data at least has the hex equivalents of the non-English characters in it. The print, however, has done some conversion that I'm not sure about.
In any event, this ends up as pretty much junk data.
I'm sure there's a simple conversion I'm missing here. I've butted my head up against Unicode::String for awhile, but the results were never satisfactory.
Any wisdom is very much appreciated.
Regards,
SheridanCat
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.