#!/usr/bin/env perl use strict; use warnings; my $VAR1 = ... your posted data here ...; my @records = @$VAR1; for my $index (0 .. $#{$records[0]}) { print "$records[0][$index][1] -> $records[0][$index][0]\n"; }

Output:

Science | -> Sciences | Research | -> Recherche | Artificial Intelligence -> Intelligence artificielle

So, that gets the job done. With a better understanding of the data you start with, I expect that could probably be greatly simplified.

Using the same name (i.e. decoded_json) for both a scalar and an array variable has a high chance of tripping you up somewhere in the code. You show Dumper $record in your posted code but later you say "Dump was of \@records".

I'm also getting the sense that you're not overly familiar with handling arrays and arrayrefs. Take a look at perlintro; its "Perl variable types" section; the "Arrays" subsection; then follow the "Exhaustive information ..." links at the end (i.e. right before the "Variable scoping" heading).

— Ken


In reply to Re: Parsing Array of arrays from json file by kcott
in thread Parsing Array of arrays from json file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.