in reply to Re^5: Encode throws "Wide character in subroutine entry" when using XML::Simple
in thread Encode throws "Wide character in subroutine entry" when using XML::Simple

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; }