in reply to Printing in a WHILE loop

Your biggest (bug causing) problem is the use of:
length[@data_array]
instead of
length (@data_array)
There are other style-related issues, primarily dealing with localizing the scope of declared variables, and using a "c-style" "for" loop where a "perl style" would be more appropriate. Let me know if you need elaboration on either point.

UPDATE: length (@data_array) will not give you expected results either . (Thanks choroba for pointing that out) ; use

scalar(@data_array)
instead.

This is because length() takes a scalar. These statements are equivalent (return the same value):

length (@data_array) == length (scalar @data_array)
So the value returned by length is the length in bytes of the size of the array.
I.e. if there are 900 elements in the array, length() would return "3" (Whereas scalar() would return 900).

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Replies are listed 'Best First'.
Re^2: Printing in a WHILE loop
by choroba (Cardinal) on May 27, 2014 at 08:03 UTC
    length @array really? It might be useful in some other languages, but in Perl, length is not scalar.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      'Tis difficult to get rid of old habits, learned many years ago. Perl is something I go back to from time to time, and therefore is always relatively "new" to me.
Re^2: Printing in a WHILE loop
by gaseous1 (Novice) on May 27, 2014 at 05:32 UTC
    Thanks for your comments, as they have been most helpful. I'd happily take any further suggestions you have.