in reply to Parsing Array of arrays from json file

Hi,

Your program is well structured and you correctly are printing out the array to debug. But the dump shows that each record is itself an array of arrays, so you need one more level of dereferencing.

Change line 25 to

print "Translation for $record->[0][1] is $record->[0][ +0]\n";

Hope this helps!

edit: got the indices the wrong way around


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Parsing Array of arrays from json file
by Anonymous Monk on Sep 12, 2021 at 10:24 UTC

    Thank you. This is a good point. However, the script does not loop correctly through @records (only first element is printout)

      Since the structure is one level deeper than you thought, you need to add another loop. Try this:

      my @categories = $decoded_json[0]; foreach my $category (@categories){ foreach my $record (@$category) { print Dumper $record; print "Translation for $record->[0] is $record->[1 +]\n"; } }

      Hope this helps!


      The way forward always starts with a minimal test.