SethCalkins
SethCalkins

Reputation: 53

Error: Type of arg 1 to each must be hash (not hash element)

I'm getting this error when attempting to run this script - on this line

Type of arg 1 to each must be hash (not hash element)

    while (my ($action, $value) = each($cameras{$camera}{$mode})) {

How do I fix this error?

Upvotes: 2

Views: 2781

Answers (2)

TLP
TLP

Reputation: 67900

Assuming that $cameras{$camera}{$mode} is a reference to a hash:

each ( %{ $cameras{$camera}{$mode} } );

As the error says, type of arg 1 to each must be a hash (not a hash ref).

If it is not a hash ref, then you cannot use each on it.

Upvotes: 2

toolic
toolic

Reputation: 62037

Dereference the hash:

 while (my ($action, $value) = each(%{ $cameras{$camera}{$mode} })) {

Upvotes: 5

Related Questions