This is just a piece of code where I am getting this error. Below I have attached my code including all the models I have used.

use XML::Simple; use Data::Dump "pp"; use Text::CSV; my $csv = Text::CSV->new({ binary => 1, auto_diag => 1, eol => "\n"}) or die "Cannot use CSV: " . Text::CSV->error_diag(); # open in append mode open my $fh, ">>", "file1.csv" or die "Failed to open file: $!"; $csv->print($fh, [ "Drug Name", "Drug Bank ID", "Category", "Pubmed ID +" ]); #--close $fh; @wantedcat = ("Blood", "Thrombus", "Thrombosis", "Anticoagulation", "C +oagulation", "Anticoagulants", "Antithrombins"); my $simple = XML::Simple->new(); my $tree = $simple->XMLin('database-01.xml'); #print pp($tree); $alldrug = $tree->{drug}; #print pp($alldrug); @allkeys = keys %$alldrug; #print scalar @allkeys; for $i (@allkeys){ #print $i; #print \n; @matchedcat = (); #if ($i eq "Cetuximab"){ $isEmpty = pp($tree->{drug}->{$i}->{categories}->{category}); if ($isEmpty eq "undef"){ } else { $isArray = $tree->{drug}->{$i}->{categories}->{category}; if (ref($isArray) eq "ARRAY"){ for $o (@{$tree->{drug}->{$i}->{categories}->{category}}){ #print pp($o); #print "\n"; $cat = $o->{'category'}; #print "$cat\n"; for $i (@wantedcat){ if ($cat eq $i){ push(@matchedcat, $cat); } } } } else { #print "$i is HASH\n"; #print pp($isArray); $cat = $isArray->{'category'}; #print $cat; for $i (@wantedcat){ if ($cat eq $i){ push(@matchedcat, $cat); } } } #print scalar @matchedcat; if (scalar @matchedcat > 0){ $count = $count + 1; $name = $i; #print "$name \n"; $category = ""; for $x (@matchedcat){ $category = $category . "$x,"; } $category =~ s/,$//; #print "$category\n"; # ### --- print all IDs of drug $ids = ""; $pids = ""; $idArray = $tree->{drug}->{$i}->{'drugbank-id'}; if (ref($idArray) eq "ARRAY"){ for my $s (@{$tree->{drug}->{$i}->{'drugbank-id'}}){ if ((ref($s) eq "HASH")){ $id = pp($s->{'content'}); $id =~ s/"//g; #print $id; #print "\n"; $ids = $ids . "$id,"; } else { #print $s; #print "\n"; $ids = $ids . "$s,"; } } } else { #print pp($idArray); $id = pp($idArray->{'content'}); $id =~ s/"//g; $ids = $ids . "$id,"; } $ids =~ s/,$//; #print $ids; #print "\n --- THE END --- \n"; $pidEmpty = pp($tree->{drug}->{$i}->{'general-references'}->{artic +les}->{article}); if ($pidEmpty eq "undef") { }else{ $pidArray = $tree->{drug}->{$i}->{'general-references'}->{arti +cles}->{article}; } if (ref($pidArray) eq "ARRAY"){ for $y (@{$tree->{drug}->{$i}->{'general-references'}->{articl +es}->{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/,$//; #print $name, $ids, $category, $pids; #open my $fh, ">>", "$file1.csv" or die "Failed to open file: +$!"; $csv->print($fh, [ $name, $ids, $category, $pids]); #close $fh; } } } print "DONE."; close $fh;

In reply to Re^4: HASH value error by pdahal
in thread HASH value error by pdahal

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.