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

I am here for to ask how to do something. The code below won't really run, and I don't expect you to make it run. You cannot without what I call $view. I here to ask you to do the DO SOMETHING below, as GrandFather, Xiong and others have told me to give a skeleton code of my question. Basically, I don't know how to throw out values from an array inside a hash which is inside another hash which is inside another array. Make sense? I didn't make the damn log file this way. It is made by UniData by a standard called NetCDF which is apparently a Universal format to store scientific data. When you put that log file into Perl it becomes a WTF of nested hashes and arrays. Hence why I hate my life right now.

My log looks similar (not exact)to this $view below. I made this up. It's not exact. It is not for the code below. The actual values are Little Endian HEX which will make you want to kill yourself. I did my best to give you a description of how my log looks like below as GrandFather and others have asked me to. I have few million records in my log file. The log contains two types of logcodes. In my code which is huge, I was able to cut short the log file short of pieces of 1000 records at a time (which contains records of both logcodes) and put it $view as below to work with. Any more records and my 12 Gig computer will run out of memory. It's an Array of hashes of hashes of an array if that makes any sense. (all this is a continuation of my CDMA problem, which is astronomical). So the log or $view sorta looks like this below in simple form.

%{$view} = ( 108A => {4=>[ 52, 54, 56.5, 34 ]}, 108A => {4=>[ 23, 55 ],6=>[21, 55]), 1069 => [ 45.1, 33], 1069 => {4=>[ 45, 29.2, 36], 6=>[33, 65, 87 ]}, 1069 => {4=>[ 47, 29, 39, 13.6 ]}, 108A => [ 34, 33], 1069 => {4=>[ 31, 32.3, 51], 6=>[23, 45, 12.5], 7=>[23,45.6,12 +]}, 1069 => {4=>[ 35.1, 22, 40], 9=>[12, 12, 11.5] } );
1. Some explanation of variables and subroutines used below. 2. view is an array of different logs and is sorted based on timestamp. 3. nextLog is an object of getNextLogFromView(). 4. subroutine getNextLogFromView($view) gets one entire log of a certain logtype at a time. I have two log types. Either #108A or 1069. #subroutine getLogCode gets the logcode. 5. @pns below stand for the second hash inside the first hash. or key of the first hash from above example. In #our case 4,6, 7, and 9. 6. numFingers below stand for the number of hashes there is inside the first hash. Or number of keys of the first hash. #4, 6, 7 and 9 are secondary hashes. sometimes there are 1 or 2 or 3 are there. upto 6 is possible. 7. In my case, there's upto 0-6 secondary hashes and upto 0-8 values is possible inside each secondary hashes.

do{ my $tmp=$nextlog->getNextLogFromView($view); if($tmp ne -1){ if(getLogCode($tmp) eq 108A){ $obj = parse0($tmp); my @pns = keys(%{$obj->{sectors}}); for(my $i=0;$i<$obj->{numSectors};$i++){ #for each sector my $sector = $pns[$i]; for(my $j=0;$j<$obj->{sectors}->{$sector}->{numFingers} +;$j++){ $myc2i=$obj->{sectors}->{$sector}->{$j}->{c2i}; DO SOMETHING #<--- Not sure where to put this. I wan +t help to throw out all the values of myc2i for each occurance of log +code of type 108A and then add it with the average of the two values +inside logcode of type 1069. Fml. And that is only phase 1. } } if(getLogCode($tmp) eq 1069){ $obj = parse1($tmp); for (my $j=0;$j<2;$j++){ $averageAgc=$obj->{$j}{'rxAgc0'}; #<-- I was trying to + add the two values together and throw out the sum to some variable. +I also want to store the values of the last occurance of 1069 somepla +ce in order for DO SOMETIHNG to fetch it to add them. } } } } while($tmp ne -1); sub DO SOMETHING{ my $multipath = shift; my ($calc); for (my $i=0; $i < $multipath->myc2i; $i++) { #NOT SURE HOW TO ADD average from 1069 (which has two values) with + every single myc2i or values the array inside second hashes. } }

I am ESL. I did my best to explain my need. :( If somebody here can make a $view to actually run this code, you may, i tried and feel like I will break the existing code above if I show you to help you help me.

  • Comment on Need help to fetch value from an array inside a hash which is inside another hash of a Bigger array. NetCDF file format.
  • Select or Download Code

Replies are listed 'Best First'.
Re: Need help to fetch value from an array inside a hash which is inside another hash of a Bigger array. NetCDF file format.
by Xiong (Hermit) on Nov 17, 2011 at 03:08 UTC

    my $extract = $object->[$index_a]{$key_b}{$key_c}[$index_d];

    Feste: Misprison in the highest degree. Lady, cucullus non facit monachum. That's as much to say as, I wear not motley in my brain....