Trying to loop through an array of hashes and getting an error message that I don’t understand.
Below is the code that creates the array of hashes, using Dumper It appears to have all every thing in it. And like this it runs fine.
while ($getAdUserInfo->fetch()){
$name = $name || '';
$isactive = $isactive || '';
$loginid = $loginid || '';
$account_status = $account_status || '';
$password = $password || '';
#print "$name, $isactive, $loginid, $account_status, $password\n";
my %row = (
name => $name,
isactive => $isactive,
loginid => $loginid,
account_status => $account_status,
password => $password,
);
push(@adUserInfo, %row);
}
But if I add this code to loop through it
for my $rowRef (@adUserInfo) {
print $rowRef->{password};
}
I get this error Can’t use string (“password”) as a HASH ref while “strict refs” in use at adempiereToExo.pl line 64
Now I have done a bit of reading on this error and most of the time it looks like it happens when someone has something in the array that is not a hash ref. But I don’t think that is the case here. I am extremely new to Perl so I could be wrong. Also it is always the last element in the hash that it moans about?
I Know there are a lot of people asking about this error, But I have read through a lot of answers and still cannot figure it out.
Change this:
(which means “expand
%row‘s keys and values out into a list, and add all of them to@aduserInfo“; you can add aprint "@adUserInfo\n"to get a clearer idea of that) to this:(which means “create a reference to
%row, and add that reference to@aduserInfo“).That’s arbitrary. Hashes are unordered, so there’s no concept of a “last element”.