re: By the way, while ($names$arraycnt ne '') is an infinite loop. Uninitialized entries in an array are undef, not ''.
just tried something after you said this, i.e. got the loop to count and print the number every time it loops and it only counts to the exact number of the fields in the db, so it must have read the undef to equal ''?