$VAR1 = [
{
'ID' => [
'1',
1,
0,
1,
1,
0,
1,
1,
1,
1,
1,
0,
0,
1,
1,
1,
1
],
'Circle' => 4,
'Triangle' => 0,
'Rectangle' => 4,
'Square' => 4
},
{
'ID' => $VAR1->[0]{'ID'},
'Circle' => 4,
'Triangle' => 0,
'Rectangle' => 0,
'Square' => 4
},
####
use strict ;
use warnings ;
use Data::Dumper ;
open my $dataIn1, "<", "Attributes_ID.txt" or die "NO ID FILE: $!";
open my $dataIn2, "<", "Attributes.txt" or die "NO ATTR FILE: $!";
my $data = () ;
my $attrs = () ;
sub getdata {
my ( $fileName, $type ) = split /\t/, $_[1] ;
push @{$data}, $type unless !defined $fileName ;
}
sub getattrs {
my @attrs = split /\t/, $_[1] ;
#shift @attrs ;
push @{$attrs}, \@attrs unless !defined $attrs[0] ;
}
while( <$dataIn1> ) {
chomp ;
getdata( 0, $_ ) ;
}
while( <$dataIn2> ) {
chomp ;
getattrs( 0, $_ ) ;
}
my @result;
for( my $j = 0 ; $j < @{$attrs} ; ++$j ) {
my %subres ;
@subres{@{$data}} = ( 0 ) x @{$attrs->[0]} ;
$subres{ID} = $attrs->[0] ;
for( my $i = 1 ; $i < @{$attrs->[$j]} ; ++$i ) {
if ( $attrs->[$j][$i] == 1 ) {
++$subres{ $data->[$i-1]} ;
}
} ;
push @result, \%subres ;
}
print Dumper(\@result) ;
####
{5}{
'Circle' => 0,
'Triangle' => 0,
'Rectangle' => 0,
'Square' => 0
},
{6} {
'Circle' => 0,
'Triangle' => 0,
'Rectangle' => 0,
'Square' => 0
},
{7} {
'Circle' => 4,
'Triangle' => 4,
'Rectangle' => 0,
'Square' => 4
},
####
FILE CATEGORY ATTRIB SCORE
1.file.ext Square 1 1
2.file.ext Triangle 1 0
3.file.ext Circle 1 1
4.file.ext Square 1 1
5.file.ext Triangle 1 0
etc...