Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: I get "not a HASH reference" when parsing an XML file

by choroba (Cardinal)
on Apr 10, 2020 at 23:43 UTC ( [id://11115352]=note: print w/replies, xml ) Need Help??


in reply to I get "not a HASH reference" when parsing an XML file

XML::Simple itself tells you not to use it.

You can use XML::LibXML instead:

#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => shift); for my $main_target ($dom->findnodes('/Targets/main_target')) { say "Main Target Name: ", $main_target->findvalue('main_target_nam +e'); for my $target ($main_target->findnodes('target')) { my $target_name = $target->findvalue('target_name'); say "\tTarget Name: $target_name"; say "\t\tSub Target Name: ", $_->findvalue('sub_target_name') for $target->findnodes('sub_target'); } }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found