choroba has already pointed out that you have made a poor choice of modules. One of the problems with XML::Simple is that it is often difficult to dereference the complex data structure that it creates. That is true in your case. You have many more dereferencing mistakes than you realize. Your program gives up when it tries to execute the first one. The common theme in all your errors is your failure to take advantage of the dereferencing that has already been done. Here is a corrected version.
#!/usr/bin/env perl use strict; use warnings; # use module use XML::Simple; use Data::Dumper; # create object my $xml = new XML::Simple; # read XML file my $xmlData = $xml->XMLin( "./xuo.xml", forcearray => 1 ); # print output # print Dumper($data); #print Dumper($xmlData); 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] ; $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] ; $target_name = $target->{target_name}[0]; print " Target Name : ", $target_name, "\n"; #if ( exists $main_target->{target}->{sub_target} ) if ( exists $target->{sub_target} ) { #foreach $sub_target ( @{ $main_target->{target}->{sub_tar +get} } ) foreach $sub_target ( @{ $target->{sub_target} } ) { #print " Sub Target Name : ", $sub_target, "\n"; print " Sub Target Name : ", $sub_target->{sub_target_name}[0], "\n"; } } } } exit;

OUTPUT:

Main Target Name : Instance Target Name : estspc_netlist Target Name : ibitmap Target Name : liberty Sub Target Name : nldm_liberty Sub Target Name : ccs_liberty Main Target Name : Validation Target Name : bmval Sub Target Name : bmval_lvs Sub Target Name : bmval_sim
Bill

In reply to Re: I get "not a HASH reference" when parsing an XML file by BillKSmith
in thread I get "not a HASH reference" when parsing an XML file by xuo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.