in reply to How can I make a string unique (quicker than my approach at least)
Quick and dirty. If the order of the names matter, this won't work. If there are duplicate ID tags, this won't work.
use warnings; use strict; my %seen; while (my $line = <DATA>) { chomp $line; my ($id, $data) = split /\s+/, $line; next if ! $id || ! $data; $seen{$id}{$_}++ for split /-/, $data; } for my $id (sort keys %seen) { printf( "%s\t%s\n", $id, join '-', keys %{ $seen{$id} } ); } __DATA__ ID1 nick-john-helena ID2 george-andreas-lisa-anna-matthew-andreas-lisa ID3 olivia-niels-peter-lars-niels-lars-olivia-olivia
Output:
ID1 helena-nick-john ID2 george-lisa-anna-matthew-andreas ID3 niels-peter-lars-olivia
|
|---|