Shiping Wang wrote:
: Yes, but it start @P = 0 .. 89;
I might use the any() function available in List::MoreUtils.
I try to avoid flag like the plague.
use List::MoreUtils 'any';
my @P = (
0.06, 0.04, 0.98, 0.12, 0.02, 0.98, 0.11, 0.25, 0.36,
0.01, 0.01, 0.01, 0.02, 0.01, 0.05, 0.056, 0.046, 0.98,
0.12, 0.002, 0.06, 0.04, 0.98, 0.12, 0.02, 0.98, 0.11,
0.25, 0.36, 0.01, 0.01, 0.01, 0.02, 0.01, 0.05, 0.056,
0.046, 0.98, 0.12, 0.002, 0.06, 0.04, 0.98, 0.12, 0.02,
0.98, 0.11, 0.25, 0.36, 0.01, 0.01, 0.01, 0.02, 0.01,
0.05, 0.056, 0.046, 0.90
);
my $cutoff = 0.01;
my @result;
foreach my $i ( 0 .. 5 ) {
if ( any { $_ <= $cutoff } $P[$i], @P[8*$i+10 .. 8*$i+17] ) {
push @result, 1;
} else {
push @result, 0;
}
}
print join( "\t", @result ), "\n";
__END__
I might also try a subroutine to process each array.
my @result;
foreach my $i ( 0 .. 5 ) {
push @result, cutoff( [ $P[$i], @P[8*$i+10 .. 8*$i+17] ] );
}
print join( "\t", @result ), "\n";
sub cutoff {
my $array_ref = shift;
return any { $_ <= 0.01 } @$array_ref ? 0 : 1;
}
__END__
Or even this (if you can understand it in six months):
my @result =
map
cutoff( [ $P[$_], @P[8*$_+10 .. 8*$_+17] ] ),
0 .. 5;
print join( "\t", @result ), "\n";
sub cutoff {
my $array_ref = shift;
return any { $_ <= 0.01 } @$array_ref ? 0 : 1;
}
__END__