Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: json data: dereferencing arrays

by hdb (Parson)
on May 14, 2013 at 11:01 UTC ( #1033447=note: print w/ replies, xml ) Need Help??


in reply to json data: dereferencing arrays

You got the levels wrong. Change $s->{BLOCKS} to $p->{BLOCKS} and $b->{PDB_ID} to $p->{PDB_ID} and $blocks[$p][$b]{PSTART} to $blocks[$b]{PSTART}.

UPDATE: I got them wrong as well. Here is code that works:

my $position = 1200; for my $s (@$data) { next unless $s->{PROT_NAME} eq 'ALK'; foreach my $p (0 .. $#{$s->{PDBS}}) { foreach my $b (0 .. $#{$s->{PDBS}[$p]->{BLOCKS}}) { my @blocks = @{ $s->{PDBS}[$p]->{BLOCKS}}; if ($position >= $blocks[$b]{PSTART} && $position <= $ +blocks[$b]{PEND} ){ print ($s->{PDBS}[$p]->{PDB_ID},"\n");} } } }


Comment on Re: json data: dereferencing arrays
Select or Download Code
Re^2: json data: dereferencing arrays
by hulketa (Initiate) on May 14, 2013 at 12:46 UTC
    uuoouu thank you so much!!!! I can see my errors now! you save my life!!! THANKS THANKS!!

      No reason to get excited. Here is how I would usually do it by iterating directly over the structure.

      my $position = 1200; for my $s (@$data) { next unless $s->{PROT_NAME} eq 'ALK'; foreach my $p ( @{ $s->{PDBS} } ) { foreach my $b ( @{ $p->{BLOCKS} } ) { if ($position >= $b->{PSTART} && $position <= $b->{PEND} ) +{ print ($p->{PDB_ID},"\n"); } } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033447]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-08-20 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls