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

I have a class that uses XML::Twig to parse a bunch of log file information (you may have seen an earlier post from me this week). Once I got my code working with scripts to test it, I rolled the same code into a CGI script. I get an error from XML::Parser::Expat that looks just like the following:
Can't use string ("<logReader><log date="20010521-") as a symbol ref w +hile "strict refs" in use at /usr/local/lib/perl5/site_perl/5.6.0/sun +4-solaris-thread/XML/Parser/Expat.pm line 456.
First of all, I am not using strict refs (vars, though), it is being set withing XML::Twig. This code behaves differently when being run from the command line (something I am told to expect by some).
The string it is referring to is the XML that I sent to the Twig->parse() command.

On an interesting side note, this is the first time I have written a CGI program, in spite of the fact that I have developed huge provisioning systems, servers, distributed message brokers, etc. all in Perl. I figured it was time for step 1 now that I have been a full time Perl developer for many years. :-)
DrSax

Replies are listed 'Best First'.
Re: XML::Twig-parse() error under CGI
by epoptai (Curate) on May 25, 2001 at 00:28 UTC
    The string it is referring to is the XML that I sent to the Twig->parse() command.

    Are you sure you're sending valid XML to the parser? I've gotten this bewildering error before and it had nothing to do with symbolic references, but was caused by feeding the parser bad XML.

    --
    Check out my Perlmonks Related Scripts like framechat, reputer, and xNN.

      The exact same string works when sent from a script on the command line.
      DrSax
Re: XML::Twig-parse() error under CGI
by rpc (Monk) on May 24, 2001 at 22:29 UTC
    A friend of mine experienced this same problem. The error is generated within an eval in Expat.pm, while the module is trying to figure out what kind of data you passed it. Do you have a $SIG{__DIE__} handler set up that isn't checking to see if the die was generated by eval? Or, are you running under mod_perl?

    I'm not sure if it will work, but you might try putting Twig->parse() in its own block, with all warnings turned off. If this doesn't work, maybe you can register your own $SIG{__DIE__} handler (if you aren't already, but something else is) that checks $^S.

    hth,
    --rpc

      rpc,
      Thanks for the input. I tried putting it in its own block with no strict qw(refs), and it made no difference. I am not running under mod_perl.I will send a msg to mirod and see if he has anything to say about it. In the meantime I will register my own $SIG{__DIE__} handler and see if that fixes it.
      Thanks for the assist!
      DrSax
Re: XML::Twig-parse() error under CGI
by mirod (Canon) on May 25, 2001 at 15:02 UTC

    I am afraid this might be a mod_perl / Expat problem.

    <mode type="cover_my_a**">XML::Twig does not modify the string in any way before it is sent to XML::Parser (or actually to XML::Parser::Expat).</mode>

    That said I have never used XML::Twig under mod_perl and I am not familiar with what can go wrong when you do so.

    What I know is that there are version conflicts between the version of Expat that comes with XML::Parser and the one that comes with Apache (yes Apache comes with Expat, and it is installed by default as a static library). The only way to be really sure that everything is fine is, IIRC, to first install the lastest Expat from sourceforge, then to install XML::Parser 2.30, then to recompile apache with Expat as a dynamic library. Instructions to do so can be found on Matt Seargeant's AxKit site at http://axkit.org/faq.xml. I can't say that's the problem, but I would definitely not rule it out. Try doing /path/to/apache/bin/httpd | grep -i XML and if you get any result then it might be the problem.

    If this fails then post (or send me) the code.

      Michel,
      The error message I am getting shows that the Expat.pm is at /usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris-thread/XML/Parser/Expat.pm which is the precise path of the 2.30 version. Wouldn't that be indicative of the fact that I am not getting a different Expat via the WebServer?

      Also, I am being told that I am not running mod_perl in this case by those who administer the webserver here. I have to take that on faith because I have had little to do with the setup of our web environment, but I trust those who are saying it.

      One interesting fact is that after this error hits the browser the code works just fine. I'm glad that the code works (epecially the XML::Twig part, right?) but seeing the error is a concern.

      By the way, as you may recall in my former message to you, your recommendation was to set the handler on the higher level branch of the messages. The metric on that is that it takes about a minute to browse 2000 log entries, where it took about 10 seconds to only hit the exceptions. From my customer's point of view, it shouldn't be a problem, as the average daily log traffic will be more like 50 to 100 log entries.

      Let me know if you think of anything else, or have any other ideas. You have been a big help to me, Michel.

      Brian a.k.a. DrSax
Re: XML::Twig-parse() error under CGI
by aardvark (Pilgrim) on May 25, 2001 at 02:36 UTC
    DrSax can you post some of your code, so we can see what is going on? It will make it a lot easier for us to debug the problem.

    Get Strong Together!!