2 - 1 1 1 1 1
1 - 1 1 1 2 8
1 - 1 5 6 12 12
####
2 - 1 1 1 1 1
1 - 1 2 1 1 8
1 - 1 6 5 12 12
####
2 - 0 0 0 0 0
2 - 1 1 1 1 1
1 - 1 2 1 1 8
1 - 1 6 5 12 12
####
use warnings;
use strict;
my @AllPatterns = (
'1 2 1 1 8',
'0 0 0 0 0',
'1 6 5 12 12',
'0 0 0 0 0',
'1 1 1 1 1',
'1 1 1 1 1',
);
{ # limit scope of array processing variables
my $biggest = 10; # biggest number (most decimal digits)
my $fmt = join ' ', ("%0${biggest}ld") x 5;
my $lead0s = qr{ \b 0{1,@{[ $biggest - 1 ]}} }xms;
my %seen; # unique-ifing hash
@AllPatterns = # 7. save to original array
map { "$seen{$_} - $_" } # 6. make into final format
grep { not $seen{$_}++ } # 5. only patterns not seen yet
map { s{$lead0s}{}xmsg; $_ } # 4. remove padding
sort # 3. lexicographic ascending sort
# map { print "'$_' \n"; $_ } # 2b. FOR DEBUG
map { sprintf $fmt, split } # 2. pad fields to constant widths
@AllPatterns # 1. for all patterns...
;
} # end scope of array processing variables
print join("\n", @AllPatterns), "\n";