Perl: Couldn't open encmap ascii.enc
I'm running perl 5.8.9 in FreeBSD 7.4. And I'm using the XML/Parser.pm module.
It used to work, but today I got th开发者_如何学编程e following error message: Couldn't open encmap ascii.enc: No such file or directory at /usr/local/lib/perl5/site_perl/5.8.9/mach/XML/Parser.pm line 187
Any idea why the error happens? Thanks a lot.
ASCII is natively supported by expat, so it shouldn't be looking for a .enc
file for it.
Expat has built-in encodings for: `UTF-8`, `ISO-8859-1`, `UTF-16`, and `US-ASCII`. Encodings are set either through the XML declaration encoding attribute or through the ProtocolEncoding option to XML::Parser or XML::Parser::Expat.
For encodings other than the built-ins, expat calls the function load_encoding in the Expat package with the encoding name. This function looks for a file in the path list @XML::Parser::Expat::Encoding_Path, that matches the lower-cased name with a '.enc' extension. The first one it finds, it loads.
Maybe the XML document specified
encoding="ASCII"
instead of
encoding="US-ASCII"
The library doesn't recognise that they should be treated the same.
$ perl -MXML::Parser -e'
XML::Parser->new->parse(
qq{<?xml version="1.0" encoding="$ARGV[0]"?><root/>});
' US-ASCII
$ perl -MXML::Parser -e'
XML::Parser->new->parse(
qq{<?xml version="1.0" encoding="$ARGV[0]"?><root/>});
' ASCII
Couldn't open encmap ascii.enc:
No such file or directory
at .../XML/Parser.pm line 187
精彩评论