Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Array of hashes?

by haukex (Archbishop)
on Jan 04, 2021 at 17:49 UTC ( [id://11126304]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Array of hashes?
in thread Array of hashes?

I read the json data like this

That code works for me (Update: assuming the code you showed in the parent node is what produced the output shown in the root node). Please show a representative Short, Self-Contained, Correct Example that reproduces the problem you're having and that includes sample input, expected output, and actual output including any error messages (How do I post a question effectively?).

use warnings; use strict; use Data::Dumper; use JSON::PP qw/decode_json/; my $json = <<'JSON'; { "myData" : [ { "Lang4":"ok", "Lang9":"well", "Lang7":null, "Lang6":null }, { "Lang4":"one", "Lang9":"two", "Lang7":null, "Lang6":null } ] } JSON my $data = decode_json( $json ); my $definition= $data->{'myData'}; my @definition=@$definition; print Dumper \@definition; foreach my $record (@definition) { print $record->{Lang4}, "\n"; }

Output:

$VAR1 = [ { 'Lang6' => undef, 'Lang9' => 'well', 'Lang4' => 'ok', 'Lang7' => undef }, { 'Lang6' => undef, 'Lang9' => 'two', 'Lang7' => undef, 'Lang4' => 'one' } ]; ok one

Replies are listed 'Best First'.
Re^4: Array of hashes?
by Anonymous Monk on Jan 04, 2021 at 19:08 UTC

    Happy that at the end my approach was okay. Did not worked though in the final application with some more passing of the REF among subrutines. Cleaning the code helped. Thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11126304]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-19 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found