in reply to scanning hash
I just wanted to add that ysth's solution can also be adapted in such a way that it can be applied to arrays.
Determine if all elements in @array are equal.
use strict; use warnings; my @goodarray = ( 1, 1, 1, 1, 1 ); my @badarray = ( 1, 2, 3, 4, 5 ); foreach my $aref ( \@goodarray, \@badarray ) { print SameVals($aref) ? "Good!\n" : "Bad!\n"; } sub SameVals { keys %{ { map { $_ => undef } @{ +shift } } } <= 1; }
Enjoy!\n
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: scanning hash
by Aristotle (Chancellor) on Aug 01, 2004 at 14:42 UTC |
In Section
Seekers of Perl Wisdom