in reply to Re: multiple XML fields in one line
in thread multiple XML fields in one line

Thanks a lot for your help! Much appreciated.

However, now the script is not working, it exits with an error message: "Not a HASH reference at blastHit.pl line 102." It points to this line:

push @{$ret},join '|',

Something seems to be wrong with @{$ret}; I am educating myself on how Perl handles arrays, hashes, references and such, but in the meanwhile I'd be grateful if you would share your thoughts on this. Why it is not working now when previously it worked with the single XML field?

Thanks a lot again!

Replies are listed 'Best First'.
Re^3: multiple XML fields in one line
by poj (Abbot) on Aug 08, 2014 at 17:02 UTC
    Can you provide a small sample of the XML file that fails.
    poj

      Yep, here is the first part, after the <Iteration_hits> there are lots of <Hit>-s, all with exactly the same structure, so I kept only the first two. The point is to search in the <Hit_def> of these <Hit>-s, but in the output we'd like to see the <Hit_num> and <Hsp_identity> attributes of the matching <Hit>-s too.

        This test program works against your sample data, try running it against the complete file

        #!perl use strict; use warnings; use XML::Simple; use Data::Dump 'pp'; my $blast = XMLin('BLAST1.XML'); my $hits = $blast->{BlastOutput_iterations}->{Iteration}->{Iteration_h +its}->{Hit}; my $ret; #push @ret, $_->{Hit_def} foreach (@{$hits}); foreach (@{$hits}) { push @{$ret},join '|', $_->{Hit_def}, $_->{Hit_num}, $_->{Hit_hsps}->{Hsp}->{Hsp_identity}; } pp $ret;
        poj