Hi Charles,

At 17:18 2006-9-29, Charles K. Clarkson wrote:
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__
Thank you very much for your three approaches in coding. I personally like #2 for the reason you have mentioned.

Shiping


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to