pdahal has asked for the wisdom of the Perl Monks concerning the following question:

I am a beginner in perl. I need to parse an XML file and store the results into CSV file. The problem I am facing is I am getting the output like "HASH(0x3de3350)" instead of PubMed IDs like "16466327" in CSV file. How can i handle this?

Replies are listed 'Best First'.
Re: HASH value error
by choroba (Cardinal) on Apr 29, 2017 at 06:01 UTC
    Without seeing the code, we can only guess.

    There's no general way of converting XML to CSV, especially because XML can store structured data, while CSV stores tables. You need to give more details.

    HASH(0x...) shows the variable is a hash reference. Read about them in perlreftut.

    You aren't using XML::Simple , are you? It warns against itself in the documentation.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: HASH value error
by huck (Prior) on Apr 29, 2017 at 06:03 UTC

    You are going to have to show us more of what you tried

    A scalar like "HASH(0x3de3350)" means the element is actually a pointer to a hash. Whatever you are trying to use to parse the xml file is returning more advanced structures than mere text.

    This is why you have to show us what you tried

      This is the code I am trying

      $pidEmpty = pp($tree->{drug}->{$i}->{'general-references'}->{articles} +->{article}); if ($pidEmpty eq "undef") { }else{ $pidArray = $tree->{drug}->{$i}->{'general-references'}->{articles +}->{article}; } if (ref($pidArray) eq "ARRAY"){ for $y (@{$tree->{drug}->{$i}->{'general-references'}->{articles}- +>{article}}){ if ((ref($y) eq "HASH")){ #print pp($y); #print "\n"; $pid = $y->{'pubmed-id'}; print "$pid\n"; $pids = $pids . "$y,"; } } }else{ $pid = $pidArray->{'pubmed-id'}; $pids = $pids . "$pid,"; } $pids =~ s/,$//;

        Doesnt help a bit. You havent shown us what modules you are using, where does pp() come from. you havent shown us where $tree or $i are assigned.

        you may get a clue as to what is going on if you put these two statements before what you showed us.

        use Data::Dumper; print Dumper($tree);