http://qs321.pair.com?node_id=11101982


in reply to Best method to eliminate substrings from array

How about something like this (this does depend on them being sorted shortest to longest):
my @data = sort { length($a) <=> length($b) } qw( 2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854|8W1152|8R0721|9C5344|6W6672|­9G7101|3023908|6Y1352|4P0489|27578 +03 3419308|3514531|3525716|3557019|3586192|3635776|3783741 3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854 3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854|8W1152|8R0721 3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854|8W1152|8R0721|9C5344|6W6672|­9G7101|3023908|6Y1352|4P0489|13369 +34 4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377 4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788 6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|275780 +3 6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854|8W1152|8R0721|9C5344|6W6672|­9G7101|3023908|6Y1352|4P0489|13369 +34 6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377 6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1 +F7854|8W1152 ); my %uniq; foreach my $elem (@data) { my @parts = split /\|/, $elem; foreach my $p (0 .. $#parts) { my $e = join '|', @parts[0..$p]; delete $uniq{$e} if exists $uniq{$e}; } $uniq{$elem} = 1; } print "$_\n" for keys %uniq;