Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

While running this the first two $orf with $count values ge 4 do not enter the "for" loop (it does print the newline contained in "if" statement). However all subsequent values of $count ge 4 do.
$input = 'YAVSNCKFNIEDYNNIFKVMENIRKHSNKNLNDQDELNIYLGVQSSNAKR'; $l = length ($input) - 1; ### P(a), P(b), P(turn), f(i), f(i+1), f(i+2), f(i+3) ### %aa = ( A => [1.42,.83,.66,0.060,0.076,0.035,0.058], R => [.98,.93,.95,0.070,0.106,0.099,0.085], N => [.67,.89,1.56,0.161,0.083,0.191,0.091], D => [1.01,.54,1.46,0.147,0.110,0.179,0.081], C => [.70,1.19,1.19,0.149,0.050,0.117,0.128], E => [1.51,.37,.74,0.056,0.060,0.077,0.064], Q => [1.11,1.10,.98,0.074,0.098,0.037,0.098], G => [.57,.75,1.56,0.102,0.085,0.190,0.152], H => [1.00,.87,.95,0.140,0.047,0.093,0.054], I => [1.08,1.60,.47,0.043,0.034,0.013,0.056], L => [1.21,1.30,.59,0.061,0.025,0.036,0.070], K => [1.14,.74,1.01,0.055,0.115,0.072,0.095], M => [1.45,1.05,.60,0.068,0.082,0.014,0.055], F => [1.13,1.38,.60,0.059,0.041,0.065,0.065], P => [.57,.55,1.52,0.102,0.301,0.034,0.068], S => [.77,.75,1.43,0.120,0.139,0.125,0.106], T => [.83,1.19,.96,0.086,0.108,0.065,0.079], W => [1.08,1.37,.96,0.077,0.013,0.064,0.167], Y => [.69,1.47,1.14,0.082,0.065,0.114,0.125], V => [1.06,1.70,.50,0.062,0.048,0.028,0.053],); for(my $i=0; $i < $l - 4; $i++) { my $col = 0; # reference to hashmap column 1, P(a) $orf = substr($input,$i,6); @fra = split('', $orf), "\t"; $count = count(@fra), "\t"; #characters ge 1 print $orf, " ", $count, "\n"; if ($count ge 4) { for (my $j=$i+3; $j le $l - 3; $j++) { print my $frame = substr($input, $j, 4);# print " "; print my $alpha4 = average ($frame, $col), "\n"; if ($alpha4 lt 1.00) {$j = $l}; }; print "\n"; } } exit; sub count { my $c = 0; foreach (@_) { my $p = $aa{$_}[0]; if ($p ge 1.00) {$c++}; } return $c; } sub average { my ($frame, $col) = @_; my $a = 0; @seq = split ('', $frame); foreach $_ (@seq) { $a += $aa{$_}[$col]; } return $a/(length($frame)); }

Replies are listed 'Best First'.
Re: Beginner issues!
by kcott (Archbishop) on Nov 16, 2010 at 05:41 UTC

    You have a number of issues like $count ge 4 where you are using a string operator with numerical operands.

    Check the Relational Operators and the Equality Operators in perlop.

    -- Ken

Re: Beginner issues!
by CountZero (Bishop) on Nov 16, 2010 at 07:02 UTC
    What do you hope to achieve by
    $count = count(@fra), "\t";

    The comma operator does not do what you think it does:

    Binary "," is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C's comma operator.

    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

Re: Beginner issues!
by ikegami (Patriarch) on Nov 16, 2010 at 05:41 UTC
    I don't know whether this is the issue or not, but "lt", "ge", etc should be "<", ">=", etc. The former are string comparison operators; the latter are numerical comparison operators. For example, 4 gt 10 is true.