local $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; is misplaced. You call load after the local falls out of scope, and thus after the local undid the assignment.

The point of specifying PREFERRED_PARSER is to choose the fastest parser available for XML::Simple and to avoid buggy XML::SAX::PurePerl. Since you get the the encoding error when you don't specify PREFERRED_PARSER, you must be defaulting to XML::SAX::PurePerl. I take it out of my XML::SAX configuration file so it never gets selected.

You are also using incorrect prototypes. You say your functions take no arguments, but that's obviously not true.

Fixed:

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

In reply to Re^6: Encode throws "Wide character in subroutine entry" when using XML::Simple by ikegami
in thread 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.