in reply to Loop skipping

Have you tried adding some print statements showing the values of your variables at each pass? This should help a lot with debugging (unless you are savvy with the debugger--but then why are you asking us! ;p) For instance, at loops and conditional statements, add something like:

print <<END_DEBUG if $DEBUG; \$m = $m \$n = $n \$j = $j \$row = $row END_DEBUG

The variables $m and $n are easy to mix up... if you didn't cut and paste your exact code, are you sure you haven't accidentally typed $m++ rather than $n++ somewhere? The debug output will help you locate mistakes that you can't find while staring at the code.

(Don't forget to put somewhere near the top of your code)

my $DEBUG = 1;

--Solo
--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.