I have an array of references to anonymous hashes. From the reference to that array, $allDirArray
, I want to access the value corresponding to the key 'dir'
. Currently I am getting the error:
Can't use string ("HASH(0x100878050)") as a HASH ref while "strict refs" in use at nameOfProgram.pl line 148.
My code:
my $tempDir = ${$allDirArray}[$i]{'dir'};
The error message suggests you're actually trying to use the string "HASH(0x100878050)
" as a hashref. So I suspect you've somehow managed to stringify your hashes (ie, you used them as strings, and Perl turned them into strings for you). One way this can happen is if you assign a hashref to a hash key (hash keys can only be strings), or by quoting variables in an assignment like this $array[0] = "$hashref"
.
So inside ${$allDirArray}[$i]
is a string containing "HASH(0x100878050)", literally that, in a string. Not a hash.
Best bet to confirm this is probably to dump the data structure. You can do this with Data::Dumper:
use Data::Dumper;
print Dumper($allDirArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With