in reply to Counting Array in an Array of HoA

If the caps is always large, then I would use foreach loop instead of above to test existence. Btw. this just says it is there or not, not how many times.
foreach my $key (keys %{$hash}) { my $ar = $hash{$key}; foreach (@{$ar}) { $_ eq $array->[0] && shift @{$array} && !@{$array} && last; } if (!@{$array}) { # was found in the hashes array } }
Note the above is untested. Also deletes the given array (not the ones in hash). If you want count of how many times, then need to continue to end of array in hash and recreate tester array when it is completely deleted. Also if multiple counting, then the if needs to be done differently.

EDIT: Fixed one obvious bug

Replies are listed 'Best First'.
Re^2: Counting Array in an Array of HoA
by monkfan (Curate) on May 15, 2005 at 10:06 UTC
    Hi Hena,
    I am attempting to generalize the problem above, such that now it can count support based on "string mismatch" paramaters. The code below is inspired by your posting above, and it already gives the correct answer. I know that the my code is a "idiot" solution to your ingenious approach above. I don't understand much of your code (especially that one-liner with many '&&'). I wonder how would you make my code compact like yours? I really want to learn to write my code briefly.
    Regards,
    Edward