xuo has asked for the wisdom of the Perl Monks concerning the following question:
My code :<?xml version='1.0'?> <Targets> <main_target> <main_target_name>Instance</main_target_name> <target> <target_name>estspc_netlist</target_name> <target_options>CELLS</target_options> </target> <target> <target_name>ibitmap</target_name> <target_options>CELLS</target_options> <target_options>STACK_MODE</target_options> </target> <target> <target_name>liberty</target_name> <target_options>STACK_MODE</target_options> <target_options>VT_MODE</target_options> <sub_target> <sub_target_name>nldm_liberty</sub_target_name> </sub_target> <sub_target> <sub_target_name>ccs_liberty</sub_target_name> <sub_target_options>CELLS</sub_target_options> <sub_target_options>VT_MODE</sub_target_options> </sub_target> </target> </main_target> <main_target> <main_target_name>Validation</main_target_name> <target> <target_name>bmval</target_name> <target_options>VT_MODE</target_options> <sub_target> <sub_target_name>bmval_lvs</sub_target_name> <sub_target_options>VT_MODE</sub_target_options> </sub_target> <sub_target> <sub_target_name>bmval_sim</sub_target_name> <sub_target_options>STACK_MODE</sub_target_options> <sub_target_options>VT_MODE</sub_target_options> </sub_target> </target> </main_target> </Targets>
If I comment out the lines foreach $sub_target...#!/usr/bin/env perl # use module use XML::Simple; use Data::Dumper; # create object $xml = new XML::Simple; # read XML file $xmlData = $xml->XMLin("./xuo.xml", forcearray => 1); # print output # print Dumper($data); my $main_target = '' ; my $target = '' ; my $sub_target = '' ; my $main_target_name = '' ; my $target_name = '' ; foreach $main_target (@{$xmlData->{main_target}}) { $main_target_name = @{$main_target->{main_target_name}}[0] ; print "Main Target Name : ", $main_target_name, "\n" ; foreach $target (@{$main_target->{target}}) { $target_name = @{$target->{target_name}}[0] ; print " Target Name : ", $target_name, "\n"; # if (exists $main_target->{target}->{sub_target}) # { foreach $sub_target (@{$main_target->{target}->{sub_target +}}) { print " Sub Target Name : ", $sub_target, "\n"; } # } } } exit ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I get "not a HASH reference" when parsing an XML file
by 1nickt (Canon) on Apr 10, 2020 at 17:49 UTC | |
|
Re: I get "not a HASH reference" when parsing an XML file
by choroba (Cardinal) on Apr 10, 2020 at 23:43 UTC | |
|
Re: I get "not a HASH reference" when parsing an XML file
by BillKSmith (Monsignor) on Apr 11, 2020 at 21:05 UTC | |
|
Re: I get "not a HASH reference" when parsing an XML file
by Anonymous Monk on Apr 13, 2020 at 09:33 UTC | |
by haukex (Archbishop) on Apr 13, 2020 at 09:42 UTC | |
by xuo (Acolyte) on Apr 13, 2020 at 09:47 UTC |