Reputation: 216
First off, I know this is a fairly common issue but I have looked around and can't quite seem to pinpoint why its happening to me!
I have some data I am reading from a JSON
file, basically all it is are a set of string that represent IDs.
I import it like so:
my $idFile='IDS.json';
my $idJSON;
{
local $/;
open my $fh, '<', $idFile or die $!;
$idJSON = <$fh>;
close $fh;
}
my $id_array = decode_json $idJSON;
This is what $id_array
looks like now:
$VAR1 = [
'3233',
'2758',
'2797'
];
I then save them with a MISC
tag in the form of a hash map, but this is where my "Can't use string ("3233") as a HASH ref while "strict refs" in use "
error is being thrown:
my @decodedIDS = map { $_ ->{MISC}} @{$id_array};
Anyone have suggestions as to what is causing this error? Any help is greatly appreciated, as always.
Upvotes: 1
Views: 5533
Reputation: 21666
I don't understand what you're trying to do but below is the reason of the error.
map { $_->{MISC} } @{$id_array}
means take each element from given dereferenced arrayref and access the MISC
key of that element (it is expecting the element to be a hashref). In your case the element is literal string (3233 for example). So it kinda looks like this:
3233->{MISC}
Therefore you get below error:
"Can't use string ("3233") as a HASH ref while "strict refs" in use
Upvotes: 2