Shoot! I pasted the wrong error. I meant to say that the error printed is

Cannot decode string with wide characters at C:/Perl/lib/Encode.pm line 174.

Okay, I found a way to reduplicate it. Place the following lines in a text file and save it as utf8:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<etax id="{e961ee2c-a029-489a-8bf4-3c2ecef7f019}" ettx="TL-Scriptures.ettx">

<sifx>

<LEX st="Kasulatan" id="tl" chrBrk="–—" tSt="s11"/>

<LEX st="Pambungad" id="tl" chrBrk="–—" tSt="p11"/>

<LEX st="Panimula" id="tl" chrBrk="–—" tSt="h11"/>

</sifx>

The following is the module I wrote where the error occurs:

#!/usr/bin/perl -l package SIFX; use strict; use XML::Simple; use Data::Dumper; sub new(){#scalar file name optional my $class = shift; my $self = { etaxFile => '', SIFX => {}, }; bless $self, $class; load($self,shift) if @_ ==1; return $self; } sub load(){ return -1 if(@_ == 0); my ($self, $input) = @_; my $sifx; if((substr $input, -4, 4) eq '.txt'){#if input was a file name $self->{etaxFile} = $input; open my $etax, '<utf8', $input or print "Could not open etax f +ile at __LINE__"; my $text; while($text ne '<sifx>'){#until beginning of SIFX chomp($text = <$etax>); } $sifx= '<sifx>'; do{#until end of SIFX chomp($text = <$etax>); $sifx .= $text; }while($text !~ m#</sifx>#); close $etax; } else{ $sifx = $input; } my $xml = XML::Simple->new(); $self->{SIFX} = $xml->XMLin($sifx); print "SIFX hash is : "; print Dumper($self->{SIFX}); } 1;

And you can test it with the following after changing the $testSifx variable to the path of the text file:

my $xml = XML::Simple->new(); my $testSifx = "C:\\Users\\nate\\Desktop\\testSIFX.txt"; my $sifx = SIFX->new($testSifx); print Dumper($sifx);

I apologize for the original, inadequate, inaccurate post.


In reply to Re^2: XML::Simple throws decode error in encode.pm by Anonymous Monk
in thread XML::Simple throws decode error in encode.pm by Anonymous Monk

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.