Keep It Simple, Stupid | |
PerlMonks |
RE:(3) All array elements the same? (Code explained)by Russ (Deacon) |
on Aug 01, 2000 at 20:34 UTC ( [id://25494]=note: print w/replies, xml ) | Need Help?? |
He's putting all the elements of the array into a hash,
using a hash slice @check{@arr} = @arr x 1;
Then, if there is only one key, all the values must have been identical. @check{@arr} is the "keys" part of the slice, and @arr x 1 just gives us the correct number of "values." Voila! A list of the unique elements of @arr (in keys %check). If there is only one unique element, then they are all the same. Two problems solved for the price (two lines, in this case) of one. :-) Russ
In Section
Seekers of Perl Wisdom
|
|