in reply to removing elements from an array containing duplicated patterns
Updated: Corrected an error and added the caveat.
CAVEAT: If there are any values that you wish to retain but don't care if they are duplicated (hopefully an unlikely scenario) this won't work.
With the kind assistance of bart (and the eternal patience of Zaxo!) a rather simplier solution.
#! perl -w use strict; use Data::Dumper; my @data = ('$?/1dlw&', '*%1sdh^?', '@/!1dlw\/', '$?1cgi*&', '?@1sdh%& +', '~#1xnf$%'); my $patterns = join '|', qw(1dlw 1sdh 1cgi 1xnf); my $regex = qr/($patterns)/; my %count; my @deduped = grep { /$regex/ && $count{$1} == 1 } map { /$regex/; $count{$1} ++; $_ } @data; print "'$_'\n" for @deduped; __END__ C:\test>193719 '$?1cgi*&' '~#1xnf$%'
|
|---|