flounder has asked for the wisdom of the Perl Monks concerning the following question:
In this case, I would like to pick out 1 and 6 as duplicates through the sets of data. However, 5 is not a duplicate, because I don't care about the duplicates within a set. I think the fastest way to do this is probably using the exists function with hashes, but I'm not quite sure how to do it effeciently. My sad attempt at doing this(coming from a C background) is shown below. Like I said, it works, but it's very time consuming due to the nested loops. Thanks in advance to all help!@array = ([1,2,3],[5,5,6],[1,4,6]);
Oh, and one more thing now that I see the code. The lines where I have to check for a null or space in the array. I am not quite sure how they got there, and would like to get rid of them all together. The way I enter things into the array is:my $loop_index = 0; for $comma_array (@current_case_commas) { for my $comma (@$comma_array) { if($comma != "") { for (my $i=0; $i < $loop_index; $i++) { my @other_cases_array = @{$current_case_commas[$i]}; for my $other_cases (@other_cases_array) { if($other_cases = "") { if ($comma == $other_cases) { $final_case_values_duplicate{$comma} = +(); } } } } for (my $i=$loop_index+1; $i <= $#current_case_commas; +$i++) { my @other_cases_array = @{$current_case_commas[$i]}; for my $other_cases (@other_cases_array) { if($other_cases != "") { if ($comma == $other_cases) { $final_case_values_duplicate{$comma} = +(); } } } } } } $loop_index+=1; }
Where the list is a space separated list of numbers. I am not sure why(since I'm splitting on spaces/tabs) a blank would get into the array in the first place. Thanks again for putting up with another newbie, and all your help.push @array, split(/[\s|\t]+/,$list_of_num);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing between multiple sets of data
by Masem (Monsignor) on Jun 22, 2001 at 21:41 UTC | |
Re: Comparing between multiple sets of data
by mirod (Canon) on Jun 22, 2001 at 21:47 UTC | |
Re: Comparing between multiple sets of data
by maverick (Curate) on Jun 22, 2001 at 22:57 UTC |