use strict; use warnings; my @array=({key1=>1,key2=>2},{key1=>1,key2=>3},{key1=>1,key2=>5}); print "Yes!\n" unless grep { $_->{key1} != 1 } @array;
Or, if the array is large, List::Util's first is even a better friend:
#!/usr/bin/perl use strict; use warnings; use List::Util qw( first ); my @array=({key1=>1,key2=>2},{key1=>1,key2=>3},{key1=>1,key2=>5}); print "Yes!\n" unless first { $_->{key1} != 1 } @array;
Update: Ok, I agree with holli, grep and (probably) first are loops, but not explicit loops, that was what maybe he was asking for. When I think in loops, I think in for, while and friends, and I see map, grep... more as "list transformers".
In reply to Re: Checking if all the key values are same in an Array
by deibyz
in thread Checking if all the key values are same in an Array
by perl_devel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |