helgi has asked for the wisdom of the Perl Monks concerning the following question:
Hello, fellow Monks.
I have been trying to use XML::Simple to parse and count elements from an XML file.
I am having trouble getting dereferencing the hashref structure that I get from the XMLin function. I have tried many many methods and I have read the documentation over and over again, but still no luck. Whatever I try, everything returns either empty or the reference itself.
What I want to get out is a hash %file_url, with filenames as the elements, something like
$file_url{file1.exe} = 'http://server.domain/file1.exe'; $file_url{file2.zip} = 'http://server.domain/file2.zip';
Here is the code with a much simplified version of the XML. The Data::Dumper parts are just there so that I can be sure that I am feeding the data in correctly. They are not necessary or desirable for the final code.
use warnings; use strict; ; use XML::Simple qw(:strict); use Data::Dumper; my $xml =q(<?xml version="1.0"?> <response> <files> <file file_url="http://server.domain/file1.exe"> file1.exe </file> <file file_url="http://server.domain/file2.zip"> file2.zip </file> </files> </response> ); my $ref = XMLin($xml, forcearray => [ qw(files) ], keyattr => [] ); print Dumper($ref);
Is there perhaps a better way to do this than to use XML::Simple?
I hope someone is able to help. I know this should be a really simple problem, but I'm just not getting it.
--
Regards,
Helgi Briem
hbriem AT f-prot DOT com
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Dereferencing a hashref from XML::Simple
by GrandFather (Saint) on Jul 28, 2006 at 11:03 UTC | |
by helgi (Hermit) on Jul 28, 2006 at 11:30 UTC | |
by GrandFather (Saint) on Jul 28, 2006 at 11:39 UTC | |
by helgi (Hermit) on Jul 28, 2006 at 11:35 UTC | |
Re: Dereferencing a hashref from XML::Simple
by planetscape (Chancellor) on Jul 28, 2006 at 11:12 UTC | |
by helgi (Hermit) on Jul 28, 2006 at 11:39 UTC | |
Re: Dereferencing a hashref from XML::Simple
by reneeb (Chaplain) on Jul 28, 2006 at 10:54 UTC | |
by helgi (Hermit) on Jul 28, 2006 at 10:59 UTC |