----- Original Message ----- From: "Jenda Krynicky" <je...@krynicky.cz>
To: "Perl List" <beginners@perl.org>
Sent: Tuesday, December 22, 2009 6:44 PM
Subject: Re: XML::Simple question


From:           "Mike Blezien" <mick...@frontiernet.net>
Hello,

were using the XML/Simple module to process a XML response using the code below. But for some reason the module can't read the $xmlresponse data unless we create a temp file first to store the data then pass that to the module. Is there a way to do this without having to create a temp file first. ?? Everything does work, the response is return. We used the Data/Dumper module to verify the data first.

=========================================================
my $ua  = new LWP::UserAgent;
   $ua->timeout(10);
   $ua->agent("HTTP/1.1");
my $req = new HTTP::Request 'POST' => "$xmlscript";

DO NOT QUOTE VARIABLES!

If the $variable already contains a string, you just unnecessary make
a copy. If it contains a number (well it can contain both, but I mean
the case when it contains just the number), you force Perl to convert
the number to string (and store that string alongside the number in
the variable) and make a copy of the string. And possibly later it
will have to convert the string back to number.

And these are the cases when it actually works, even if it's
inefficient. As soon as you quote like this a variable that contains
a reference or an object (a reference bless()ed to a package), you
end up with useles string, that will just look like a reference when
printed out. Do not quote variables!

my $req = new HTTP::Request 'POST' => $xmlscript;

is enough!

my $simple = new XML::Simple(KeyAttr=>[]);
# read XML file
my $xmldata = $simple->XMLin("$xmlresponse");

OK, you are safe from automatic key related transformations ... what
about tags with optional attributes? Or tags that are sometimes but
not always repeated?

See http://www.perlmonks.org/?node_id=697036

Jenda

Jenda,

thanks for the info, I nomarlly don't quote variables like that, just didn't catch that one.

Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
http://www.thunder-rain.com/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to