Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: json data: dereferencing arrays

by hdb (Prior)
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
Replies are listed 'Best First'.
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 rifling through the Monastery: (9)
As of 2015-07-31 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (275 votes), past polls