Hi
I've been trying unsuccessfully to create a new array with similar items ie
$array[0], $array[3], $array[4] based on "apples"
Help appreciated.
Regards
Clinton
My code so far:-

use strict;
my @array;
$array[0] = ["apples","oranges","plums","1"];
$array[1] = ["asparagus", "corn","peas","1"];
$array[2] = ["ham","chicken","lamb","1"];
$array[3] = ["apples","oranges","plums","1"];
$array[4] = ["apples","oranges","plums","1"];

open OUT, ">>c:/temp/result.txt";

my %found;
my @unique = grep { not $found{@$_[0]}++ } @array;
for (my $i=0; $i<=$#unique; $i++){
print OUT "Unique : $unique[$i][0] \n";
}
#Results
#Unique : apples
#Unique : asparagus
#Unique : ham


my %count;
my @repeat = grep { ++$count{@$_[0]} == 2 } @array;
for (my $j=0; $j<=$#repeat; $j++){
print OUT "Repeat : $repeat[$j][0] \n";
}
#Results
#Repeat : apples

Reply via email to