in reply to Array of hashes?
I thought it was an array of hashes, but apparently, it is not. How do I access it?
It is in fact an array of hashes, but I suspect the confusion might be coming from the fact that it's a reference to an array of hashes, as indicated by the square brackets [...]. In other words, $VAR1 here is a reference to an array, and the elements of that array are the hashes. You can access it like any reference to an array, i.e. $VAR1->[0]{Lang9} is 'well'. See perldsc, perlreftut, and perlref.
Note that you haven't shown your code, but in case it looks like print Dumper(@array);, then I would guess that you're probably doing something like my @array = decode_json(...);, which isn't quite correct, as decode_json functions typically don't return an array, but instead a reference to an array or a hash. So in other words, you should be doing my $arrayref = decode_json('[...]');, and then use the dereferencing operators that are described in the links above - for example, for my $elem (@$arrayref) or my $first = $arrayref->[0];.
Edit: Added a little bit more info to first sentence.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array of hashes?
by Anonymous Monk on Jan 04, 2021 at 17:42 UTC | |
by haukex (Archbishop) on Jan 04, 2021 at 17:49 UTC | |
by Anonymous Monk on Jan 04, 2021 at 19:08 UTC |