You never assigned to $hash_1
and $hash_2
!
my ($hash_1, $hash_2) = @_;
You have more problems than that, however, both keys
and values
in scalar context return the number of elements in a hash, so you are simply checking if both hashes are of the same size!
sub are_hashes_equal {
my ($hash1, $hash2) = @_;
{
my %set;
++$set{$_} for keys(%$hash1);
--$set{$_} for keys(%$hash2);
return 0 if grep { $_ } values(%set);
}
for my $key (keys(%$hash1)) {
return 0 if $hash1->{$key} ne $hash2->{$key};
}
return 1;
}
solved how to pass hash reference to a subroutine