Assuming that you only want to delete those rows with "wildcards" that cannot match any other row (with or without wildcards) you cannot just simply delete
all rows that contain a "9".
To check this assumption I have added an extra row of data "2 2 9 2 2". That row cannot match any of the other rows and therefore should not be deleted.
use Modern::Perl qw/2015/;
my %data;
# First we transform and load the data into a hash
while (<DATA>) {
chomp;
my $data = $_;
s/([^9 ])/[$1X]/g;
s/9/[0129]/g;
s/X/9/g;
$data{$_} = $data;
}
#Then we check if records with missing data are unique
for my $testrecord ( keys %data ) {
next unless $data{$testrecord} =~ m/9/;
for my $record ( keys %data ) {
next if $data{$record} eq $data{$testrecord}; #don't check you
+rself
if ( $data{$record} =~ m/$testrecord/ ) {
delete $data{$testrecord};
last;
}
}
}
say $data{$_} for keys %data;
__DATA__
2 2 0 1 0
2 2 0 2 1
0 2 1 1 0
0 1 1 1 0
2 2 0 0 0
2 9 0 2 1
0 2 0 1 0
2 2 0 9 0
2 2 9 2 2
Output:
0 1 1 1 0
0 2 0 1 0
2 2 0 1 0
2 2 0 0 0
2 2 0 2 1
0 2 1 1 0
2 2 9 2 2
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog:
Imperial Deltronics