6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
####
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
####
#!/usr/bin/env perl
use strict;
use warnings;
my @in_data = qw{
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
3419308|3514531|3525716|3557019|3586192|3635776|3783741
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721
3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
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|1F7854|8W1152|8
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152
};
print "Input data:\n", '-' x 40, "\n";
print "$_\n" for @in_data;
{
my @out_data;
print '-' x 40, "\nOutput data (unordered):\n", '-' x 40, "\n";
my $long_string;
for my $string (reverse sort @in_data) {
if (defined $long_string) {
next if index($long_string, $string) == 0;
}
$long_string = $string;
print "$string\n";
}
}
{
my @out_data;
print '-' x 40, "\nOutput data (ordered by first field):\n", '-' x 40, "\n";
my $long_string;
for my $string (reverse sort @in_data) {
if (defined $long_string) {
next if index($long_string, $string) == 0;
}
$long_string = $string;
push @out_data, $string;
}
print "$_\n" for sort @out_data;
}
{
my @out_data;
print '-' x 40, "\nOutput data (original order):\n", '-' x 40, "\n";
my $long_string;
my $pos = 0;
for my $pos_string (sort { $b->[1] cmp $a->[1] } map [ $pos++, $_ ], @in_data) {
if (defined $long_string) {
next if index($long_string, $pos_string->[1]) == 0;
}
$long_string = $pos_string->[1];
push @out_data, $pos_string;
}
print "$_->[1]\n" for sort { $a->[0] <=> $b->[0] } @out_data;
}
print '-' x 40, "\n";
####
Input data:
----------------------------------------
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
3419308|3514531|3525716|3557019|3586192|3635776|3783741
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721
3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
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|1F7854|8W1152|8
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152
----------------------------------------
Output data (unordered):
----------------------------------------
R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721
3419308|3514531|3525716|3557019|3586192|3635776|3783741
2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
----------------------------------------
Output data (ordered by first field):
----------------------------------------
2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
3419308|3514531|3525716|3557019|3586192|3635776|3783741
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721
3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
----------------------------------------
Output data (original order):
----------------------------------------
2N0472|6N8595|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
3419308|3514531|3525716|3557019|3586192|3635776|3783741
3T3625|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721
3T3628|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
4N4906|6N6481|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788
6N7936|6N5049|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8
R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|2757803
6Y0248|6T7765|9L1366|1189902|1413983|8B2026|1M3381|7K3377|3H5788|1F7854|8W1152|8R0721|9C5344|6W6672|9G7101|3023908|6Y1352|4P0489|1336934
----------------------------------------