I am using XML::Simple to parse some utf8 xml files. However, utf8 files with BOM cause it to crash and burn with the following error:

Wide character in subroutine entry at C:/Perl/lib/Encode.pm line 174.

The offending code is:

use XML::Simple; local $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; $xml->XMLin($file,ForceArray => ['map'], KeyAttr =>{},);

The error does NOT occur with utf8 files that have no BOM. Seems bazaar, and I have no idea what to do. Any suggestions?

Update:

It has to be the way I'm using it. Here's more context for the code I posted earlier:

In ETTX.pm:

package ETTX; use strict; use XML::Simple; local $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; use XML::SemanticDiff; sub new(){#scalar file name my $class = shift; my $self = { ettxFile => '', ettx => {}, }; bless $self, $class; load($self,shift) if @_ ==1; return $self; }; sub load(){#scalar file name my ($self, $ettxFile) = @_; print "loading $ettxFile"; open(my $fh, '<', $ettxFile); binmode($fh); my $xml = XML::Simple->new(); $self->{ettx} = $xml->XMLin($fh, ForceArray => ['map'], KeyAttr => {}, ) ->{table}; $self->{ettxFile} = $ettxFile; # print Dumper($self); 1; }

The code above was changed to to use the binmode() thing, but still fails just the same.

Called like so:

use lib 'C:\Texts\Programs'; #wherever ETTX.pm is use ETTX; my $ettxFile = 'someXMLfile.ettx'; my $ettx->load($ettxFile);
And here's a sample xml file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <ettx ver="2"> <table id="{4fa6cd7a-f7b6-416d-8f59-3acc0eab9bdb}" name="TestFile"> <level type="V"> <map sync="Title" src="someText"/> <map sync="Title Page" src="someText"/> </level> </table> </ettx>

In reply to Encode throws "Wide character in subroutine entry" when using XML::Simple by nglenn

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.