in reply to making code efficient

$cro_max is ZERO, and $i_max is unspecified (undef, value zero).

So, your loops are not doing much.

Update:Please do not modify your posts after posting (Other than to correct minor typos)
If you want to update information, post UPDATEs, like this one, that retain the context of the original post.

To answer your new question - Use sub (Soubroutines), and pass parameters.

             All great truths begin as blasphemies.
                   ― George Bernard Shaw, writer, Nobel laureate (1856-1950)

  • Comment on Re: code not working - for loops and storing values