Why am I getting an error from XML :: SAX :: PurePerl :: EncodingDetect even though I haven't loaded this module?

Below is a script I wrote to change the value of one of the parameters in an XML file located elsewhere:

#!/usr/bin/perl -w

use Cwd;
use XML::Simple;
use Data::Dumper;
no warnings;

my $before_upgrade_value = &pre_upgrade_value;
print "Value before upgrade:: $before_upgrade_value \n";

&change_value ($before_upgrade_value);

&change_value ("America");

my $after_upgrade_value = &pre_upgrade_value;

print "Value after upgrade:: $after_upgrade_value \n";
print "Done \n";

sub pre_upgrade_value {
    my $xml = new XML::Simple;

    # read XML file
    my $input_xml  = "/usr/tmp/country/CountryConfig.xml";

    my $data = $xml->XMLin($input_xml);
    my $arg0 = $data->{COMMON}->{COUNTRY_LIST}->{Value};

    print "Arg0 is $arg0 \n";
    return $arg0;
}

sub change_value {
    my $arg0 = shift;

    my $arg1 = "ENGLAND";

    my $arg2 = "/usr/tmp/country/CountryConfig.xml";

    system("perl -pi -e 's/$arg0/$arg1/' $arg2");
}

      

But I am getting the following error:

Unable to recognize the encoding of this document at / usr / local / lib / perl 5 / site_perl / 5.8.7 / XML / SAX / PurePerl / EncodingDetect.pm line 100. The document requires element [Ln: 1, Col: 0]

Can you please tell me the reason as I am not calling EncodingDetect.pm in my code?

+2


source to share


2 answers


XML :: SAX is used by XML :: Simple. From the code:

# XML::Simple requires the services of another module that knows how to parse
# XML.  If XML::SAX is installed, the default SAX parser will be used,
# otherwise XML::Parser will be used.

      



The XML :: SAX part is XML :: SAX :: PurePerl :: EncodingDetect. It looks like you have spaces at the beginning of your XML, you might find this PerlMonks node useful.

+7


source


When you use a module, you also use all the modules that it uses and all the modules that they use, and ... :)



0


source







All Articles