in reply to Checking if all the key values are same in an Array
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".
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Checking if all the key values are same in an Array
by holli (Abbot) on Apr 26, 2005 at 11:34 UTC | |
by ysth (Canon) on Apr 28, 2005 at 06:06 UTC |