[Bioperl-l] Problems with a while loop, please help

Dave Messina David.Messina at sbc.su.se
Mon Mar 16 12:16:43 UTC 2009


> Why is this loop running 3times ?


You designed the loop to execute three times with your while:

                       while ($k <= 2) {
>

If $k=0 initially, and you add 1 to k each time through the loop, how many
times will the above statement be true?

By explicitly writing $k+1 and $k+2 within the loop, you're accomplishing
the same thing that the loop is designed to do, namely accessing each
individual element of the arrays.


The questions you are asking are about fundamental aspects of Perl
programming and are not specific to BioPerl or even biological questions
answered with Perl.

This will sound harsh, but you really need to spend some time learning how
to program in Perl rather than asking questions on this mailing list.

Start by turning on warnings.

If your program had the line

use warnings;

near the top of the program, you would see the following output:

Scalar value @zwvalue1[$k] better written as $zwvalue1[$k] at test.pl line
16.
Scalar value @zwvalue2[$k] better written as $zwvalue2[$k] at test.pl line
17.
Scalar value @zwvalue1[$k+1] better written as $zwvalue1[$k+1] at test.pl
line 18.
Scalar value @zwvalue2[$k+1] better written as $zwvalue2[$k+1] at test.pl
line 19.
Scalar value @zwvalue1[$k+2] better written as $zwvalue1[$k+2] at test.pl
line 20.
Scalar value @zwvalue2[$k+2] better written as $zwvalue2[$k+2] at test.pl
line 21.
Name "main::value1b" used only once: possible typo at test.pl line 17.
Name "main::value2b" used only once: possible typo at test.pl line 19.
Name "main::value3b" used only once: possible typo at test.pl line 21.
T A A, T, A, A
Use of uninitialized value in concatenation (.) or string at test.pl line
23.
T A A, A, A,
Use of uninitialized value in concatenation (.) or string at test.pl line
23.
Use of uninitialized value in concatenation (.) or string at test.pl line
23.
T A A, A, ,


All of those warning messages are clues to some of the problems in your
code.


Dave



More information about the Bioperl-l mailing list