Help in XML::Simple
am 01.07.2005 17:42:29 von amresh
I'm looking for a simple way to process results returned from a
website via XML. I was thinking XML::Simple should be simple... but
apparently I'm even simpler than it is!
I'm having trouble figuring out how to get at the four items it
returns. Looks like $tags contains a hash which is actually a data
structure named $VAR1, which appears to define a hash, but how do I
make it work? It looked empty, but Dumper shows the contents and they
look like exactly what I want... but how do I access it???
use XML::Simple;
use Data::Dumper;
$content="
12
Decline
RE-PRESENTED CHK
99220
";
$tags = XMLin($content);
print "\n\nDumper:\n";
print Dumper($tags);
RESULT
______________________________ Results:
Dumper:
$VAR1 = {
'authcode' => 'LREADY USED',
'pnref' => '99220',
'respmsg' => 'Denied',
'result' => '12'___
'result' => '12'
};
Re: Help in XML::Simple
am 01.07.2005 18:34:23 von Jim Gibson
In article , amresh
wrote:
> I'm looking for a simple way to process results returned from a
> website via XML. I was thinking XML::Simple should be simple... but
> apparently I'm even simpler than it is!
>
>
> I'm having trouble figuring out how to get at the four items it
> returns. Looks like $tags contains a hash which is actually a data
> structure named $VAR1, which appears to define a hash, but how do I
> make it work? It looked empty, but Dumper shows the contents and they
> look like exactly what I want... but how do I access it???
>
>
>
You should have here:
use strict;
use warnings;
> use XML::Simple;
> use Data::Dumper;
> $content="
Change the above line to:
my $content ...
> 12
> Decline
>
> RE-PRESENTED CHK
> 99220
> ";
> $tags = XMLin($content);
Ditto:
my $tags = ...
> print "\n\nDumper:\n";
> print Dumper($tags);
>
>
>
> RESULT
> ______________________________ Results:
>
>
> Dumper:
> $VAR1 = {
> 'authcode' => 'LREADY USED',
> 'pnref' => '99220',
> 'respmsg' => 'Denied',
> 'result' => '12'___
> 'result' => '12'
> };
This is not what I get when I run your program. You have changed the
authcode from 'LREADY USED' to 'RE-PRESENTED CHK', and I do not get two
'result' entries. Please post exact code and output from your program
so you don't confuse those trying to help you.
The $VAR1 is a name picked by the Data::Dumper module. This is
explained in the documentation for Data::Dumper, although perhaps not
so clearly as it could be. Have you read the documentation for
Data::Dumper? If you want a more explicit output format, you can use
the following:
print Data::Dumper->Dump([$tags], [qw(tags)]);
as explained in the documentation for Data::Dumper.
XMLin returns a reference to a hash. There are examples of how to
access the data in the documentation for XML::Simple. Have you read the
documentation for XML::Simple?
As an example in your case, the authcode entry is ${$tags}{authcode}.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Re: Help in XML::Simple
am 05.07.2005 04:33:38 von Iain Chalmers
In article <010720050934236373%jgibson@mail.arc.nasa.gov>,
Jim Gibson wrote:
> In article , amresh
> wrote:
>
> > Looks like $tags contains a hash which is actually a data
> > structure named $VAR1, which appears to define a hash, but how do I
> > make it work? It looked empty, but Dumper shows the contents and they
> > look like exactly what I want... but how do I access it???
>
> As an example in your case, the authcode entry is ${$tags}{authcode}
Or, since that syntax makes me wince, $tags->{authcode}
"There's more than one way to do it"
big
--
On my tombstone they will carve, "IT NEVER GOT FAST
ENOUGH FOR ME."' - Hunter S Thompson, 1937-2005 RIP