in reply to How can I make a string unique (quicker than my approach at least)
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How can I make a string unique (quicker than my approach at least)
by hippo (Archbishop) on Apr 02, 2024 at 11:12 UTC |