This solution preserves order, if that is an issue.
johngg@aleatico:~/perl/Monks$ perl -Mstrict -Mwarnings -E 'say q{}; open my $inFH, q{<}, \ <<__EOD__ or die $!; ID1<TAB>nick-john-helena ID2<TAB>george-andreas-lisa-anna-matthew-andreas-lisa ID3<TAB>olivia-niels-peter-lars-niels-lars-olivia-olivia __EOD__ while ( <$inFH> ) { chomp; my( $pre, $post ) = split m{(?<=>)}; say $pre, join q{-}, do { my %seen; grep { ! $seen{ $_ } ++ } split m{\s?-\s?}, $pos +t } }' ID1<TAB>nick-john-helena ID2<TAB>george-andreas-lisa-anna-matthew ID3<TAB>olivia-niels-peter-lars
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: How can I make a string unique (quicker than my approach at least)
by johngg
in thread How can I make a string unique (quicker than my approach at least)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |