代码之家  ›  专栏  ›  技术社区  ›  PJ.

为什么我从XML::SAX::purePerl::encodingdetect中得到错误,尽管我没有加载该模块?

  •  2
  • PJ.  · 技术社区  · 16 年前

    下面是我为更改位于不同位置的XML文件中某个参数的值而编写的脚本:

    #!/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");
    }
    

    但我得到了以下错误:

    无法在/usr/local/lib/perl5/site_perl/5.8.7/xml/sax/pureperl/encodingdetect.pm行100识别此文档的编码。文档需要元素[ln:1,col:0]

    你能告诉我为什么我不在我的代码中调用encodingdetect.pm吗?

    2 回复  |  直到 16 年前
        1
  •  7
  •   Chas. Owens    16 年前

    XML::SAX由XML::Simple使用。从代码:

    # 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.
    

    xml::sax的一部分是xml::sax::purePerl::encodingdetect。听起来XML开头有一些空白,您可能会发现 PerlMonks node 乐于助人。

        2
  •  0
  •   brian d foy    16 年前

    当你使用一个模块时,你也使用它使用的所有模块,以及它们使用的所有模块,并且……:)