Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

XML::Simple oddness

by lindex (Friar)
on May 16, 2001 at 06:33 UTC ( #80790=perlquestion: print w/ replies, xml ) Need Help??
lindex has asked for the wisdom of the Perl Monks concerning the following question:

Well I don't really know what to say about this one because its just a bit odd, It seems that XML::Simple makes XML::Parser::Expat try to use something as a GLOB ref when it not supposed to.

lemme explain in code. we have some XML:

<root> <ROW> <confHost>barbarasueseal.com</confHost> <confBlankImage>barbarasueseal.com</confBlankImage> </ROW> ... </root>

and we have a parser script useing XML::Simple:

use XML::Simple; my($xmlstring)=<>; my($xmlObj)=XML::Simple->new(noattr=>1); my($dataref)=$xmlObj->XMLin($xmlstring);

the above code works fine for parsing the above xml but if we use the same code but in side a mod_perl env and get the string from a posted param ala:

my($xmlstring)=$r->param('xmlString');

It fails on my server with this:

Can't use string (" barba") as a symbol ref while "strict refs" in use at /usr/local/lib/perl5/site_perl/5.6.1/i586 linux/XML/Parser/Expat.pm line 456.

Its kinda weird because XML::Simple/XML::Parser::Expat inside mod_perl it wants todo this:

eval { $ioref = *{$arg}{IO}; }; undef $@;

but anywhere else it does not do this, does anyone know of any problems with XML::Simple and mod_perl and if so do you know of any workarounds/fixes.



lindex

Comment on XML::Simple oddness
Select or Download Code
Re: XML::Simple oddness
by chipmunk (Parson) on May 16, 2001 at 07:05 UTC
    mod_perl caches your Perl scripts when it runs them; this provides a nice efficiency boost, but it also has a few extra gotchas.

    You have to be very careful to initialize all your variables before you use them. Additionally, you must avoid my variables that are used both inside and outside of subroutines.

    Failing either one of those could lead to a variable holding a value that it got from a previous execution of the mod_perl script.

    How is $r declared and set in your code?

      That code was not cut and paste, I am aware of how scope works inside mod_perl $r was just an example of a Apache::Request object and is defined correctly.

      I am almost sure that this problem is not coming from my code, considering that I am using XML::Simple in the same way outside of mod_perl and it works correctly

      p.s. yes everything is defined with a my()


      lindex
        Woops... Not sure why I focused on $r, which shouldn't be related to the problem here. Sorry. :)

        All of your variables are declared with my... Are any of the variables declared outside of a subroutine, and then used inside a subroutine?

        my $var = rand; sub do_something { print "$var\n"; }
        That will lead to the 'Variable "$var" will not stay shared' error, and $var in do_something will keep the same value it had the first time do_something was called, including previous calls from earlier executions of the script in the same mod_perl fork.

        Since the behavior is different under mod_perl, my first thought is to check on the differences between running normally and running under mod_perl... If that's not it, I'll work on thinking of other possible causes for this odd behavior. Although at that point you may want someone with more experience with the XML modules. :)

Re: XML::Simple oddness
by rpc (Monk) on May 16, 2001 at 23:49 UTC
    I don't think this is necessarily a bug in Expat.pm, but it is definitely an artifact. Since the expat interface can handle so many different types of data (scalars, scalar refs, tied handles), this warning is generated when Expat.pm is trying to determine how to parse the argument given. Apparently XML::Simple passes the argument as a string, which causes that eval block to puke.

    I think mod_perl is setting up a $SIG{__DIE__} handler, and it doesn't care whether or not it occured in an eval. As to a solution, what about enclosing XMLin in its own block, that contains no strict 'refs' ?

      Well the block in XML::Parser::Expat that puks is inside a eval, how ever I did modify the $SIG{__DIE__} for mod_perl on my server, as well as recompiled mod_perl and apache to no-longer use expat-lite (the reason behind the module causeing the system to &die(); was accually a segfault due to conflicting links to different expat libs) its working now. But something should be done about the warning that XML::Parser::Expat throws :\




      lindex

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://80790]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-10-21 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls