in reply to Re^3: Help extracting pattern of data
in thread Help extracting pattern of data

Thankyou Davio. I could extract the data from the structure now. But how can I iterate through this structure now. Assume that this structure will have multiple occurances of latestTime. And I want to print all the occurances I use this line to get the data:
my $time = $structure->{latestTime};

Replies are listed 'Best First'.
Re^5: Help extracting pattern of data
by AnomalousMonk (Archbishop) on Jan 27, 2014 at 04:45 UTC
    My data is incremental so the same content with different values get appended to __DATA__ over time.

    I'm guessing a bit here, but it sounds like you will wind up with an Array-of-Hashes structure (see perldsc). If so, and building on davido's JSON code, try something like (untested):

    my @fields = qw(latestTime eCompressed eUncompressed iCompressed iUnco +mpressed); for my $i (0 .. $#$structure) { my $hr_record = $structure->[$i]; print qq{record $i: }; for my $field (@fields) { print qq{$field is $hr_record->{$field}, }; } print qq{\n}; }
      Thankyou Anomalous! It helped. I had to modify it a bit as it did not allow me to take it as an array. But the below code worked :)
      while(my $k = each %$structure) { for my $field (@fields){ print qq{$field = $structure->{$field}\n }; } }

      I will now try to work on manipulating the data from the fields output and get back if I have questions. Thanks a lot for your advice n help :)

        hey, I am having some trouble looping through the structure. The above code was fine when I had one entry of json data. But its printing the same line as many times as each key in $structure. How can I loop such that I print unique entries from the structure.