in reply to Regex: remove non-adjacent duplicate hashtags
Output:my $s = "#tag1 #tag2 #tag3 #tag1"; print qq{Original: $s\n}; my ($x, $d); map { ++$x->{$_}; $d->{$_}=$x->{$_} if $x->{$_} > 1 } split /\s+/, $s; printf qq{Uniq: %s\n}, join(' ', sort keys %$x); printf qq{Dupes found for: %s\n}, join(', ', sort keys %$d);
I am sure this can be shrunk down quite a bit, but I tried to strike a balance between terseness and readability. You can inspect $x for counts.Original: #tag1 #tag2 #tag3 #tag1 Uniq: #tag1 #tag2 #tag3 Dupes found for: #tag1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex: remove non-adjacent duplicate hashtags
by hippo (Archbishop) on Jul 24, 2022 at 09:20 UTC | |
by perlfan (Parson) on Jul 26, 2022 at 06:27 UTC | |
by AnomalousMonk (Archbishop) on Jul 26, 2022 at 10:19 UTC |