rpike has asked for the wisdom of the Perl Monks concerning the following question:

I have 2 CGI scripts written in Perl that both use XML::Simple. There's nothing fancy in there. When I run one script it runs fine but if I run the other script it complains....
Can't locate XML/SAX.pm in @INC (@INC contains: C:/Perl64/site/bin C:/ +Perl64/bin C:/Perl64/lib ........) at C:/Perl64/lib/XML/Simple.pm lin +e 369
Both scripts are in the same directory, both use the same path to the same XML document, etc..,. Why would one fail yet the other doesn't?
our $xmlSimp = XML::Simple->new(); our $xmlCont = $xmlSimp->XMLin("/baseDir/subDir/core.xml");

Replies are listed 'Best First'.
Re: Unable to locate XML.SAX
by tangent (Parson) on Dec 04, 2014 at 15:47 UTC
    The section "ENVIRONMENT" of the docs explain why this might happen. If you look at line 369 of XML::Simple it has:
    eval { require XML::SAX; }; # We didn't need it until now if($@) { # No XML::SAX - fall back to XML::Par +ser if($preferred_parser) { # unless a SAX parser was expressly r +equested croak "XMLin() could not load XML::SAX"; }
    So it would seem that in the script that fails it is defining what parser to use - have a look for the environment variable 'XML_SIMPLE_PREFERRED_PARSER' or the package variable $XML::Simple::PREFERRED_PARSER in the script.
Re: Unable to locate XML.SAX
by karlgoethebier (Abbot) on Dec 04, 2014 at 15:01 UTC
    "...There's nothing fancy in there..."

    But what's in there? I think there must be some difference. But without seeing what's in there, i can only guess.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: Unable to locate XML.SAX
by wazat (Monk) on Dec 04, 2014 at 16:02 UTC

    Add a debug statement to print out the value of @INC for both scripts. Perhaps there is a runtime difference between the two scripts.

    Are the two scripts using the same perl?

    Where is XML/SAX.pm on your system?

    Are both scripts using the same parser? Perhaps one of the scripts is setting $XML::Simple::PREFERRED_PARSER

Re: Unable to locate XML.SAX
by GotToBTru (Prior) on Dec 04, 2014 at 15:15 UTC

    Do they both call the same methods?

    1 Peter 4:10
Re: Unable to locate XML.SAX
by karlgoethebier (Abbot) on Dec 04, 2014 at 18:53 UTC

    I couldn't resist to summarize...

    1. But what's in there? (karlgoethebier)
    2. ...why this might happen... (tangent)
    3. Add a debug statement... (wazat)

    I'm curiuos about what caused your problem.

    Please see also Re: poll ideas quest 2014.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»