Something like this perhaps:
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; my @a = split; my $same = 1; for (1 .. $#a) { if ($a[$_] ne $a[$_ - 1]) { $same = 0; last; } } print "@a - elements are ", $same ? "the same\n" : "different\n"; } __DATA__ A A A A A B C A A B C
Or, if you like something a bit more esoteric:
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; my @a = split; my %h; @h{@a} = @a; my $same = keys %h == 1; print "@a - elements are ", $same ? "the same\n" : "different\n"; } __DATA__ A A A A A B C A A B C
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: Testing the Uniformity of an Array by its Elements
by davorg
in thread Testing the Uniformity of an Array by its Elements
by neversaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |