in reply to Search tab / delimited but do not display duplicate / triplicate entries
If you provide a data sample (good), try to make sure that it should return some values with your test code -> you can't match 'RTVs' if all the subject headers are 'Fw: Hey Ugly line expansion and re-offer'.
As was mentioned on CB earlier, try creating a hash to avoid duplicates. Specifically, with an array of arrays named @array,
%test_hash = (); for (@array) { if (exists ($test_hash{$_->[10]})) {next} print @{$_}; $test_hash{$_->[10]} = 1; }
Update:As per an OP request, here's melding the above code with his posted code.
my %test_hash = (); while (my $cols = $csv->getline($fh)) { last unless @$cols; next unless defined $cols->[$column_to_search] and $cols->[$column_to_search] eq $wanted_value; if (exists ($test_hash{$cols->[10]})) {next} $test_hash{$cols->[10]} = 1; for (0,1,7) { $cols->[$_] = '' unless defined $cols->[$_]; } print join(' ',$cols->[0],$cols->[1],$cols->[7],$cols->[9],$cols-> +[13],$cols->[18],$cols->[19]),"\n"; }
|
|---|