in reply to Comparing parts of 2 strings in an array and deleting one
Whenever you think "unique", think "hash".
perlfaq4 lists the common approach on how to find the unique items.
My approach to your problem would be to build a hash of
'extracted name' => 'original_line',
... and in the end, you only need to fetch the values of that hash.
If you use this approach, you lose the original order of your elements, so if that is important, you can use another approach that simply keeps track whether you've seen a particular name already:
my %seen; my @result; for my $el (@list1, @list2) { my $name= find_name_from_element($element); next if $seen{ $name }++; push @result, $el; }; # Now @result has the unique elements
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing parts of 2 strings in an array and deleting one
by Amblikai (Scribe) on Nov 29, 2013 at 14:21 UTC | |
by Corion (Patriarch) on Nov 29, 2013 at 14:25 UTC |