disulfidebond has asked for the
wisdom of the Perl Monks concerning the following question:

I wrote a script to track cell counting in my lab. It prompts the user to input the number of counts (I may do multiple at a time), then a subroutine prompts again to get each count and converts it into the total number of cells and returns it, where a final for loop displays all the elements of the array in a nice readable format. Only problem is it doesn't work. It either 1) halts arbitrarily, 2) prompts for the wrong number of counts, or 3) works correctly. I've verified the array is initialized and assigned values, and all variables are assigned values from user input or the subroutine, but I can't find where the bug is. It's probably something very simple, can someone please help?

My first recommendation is that you need use strict; in your code. This will REALLY help with the debugging.

Second: don't use the same name for scalars and arrays (e.g., my $scope_ct = @scope_ct;). It is too easy to make a mistake w/o realizing it.

EDIT: I made a few very minor changes based on the errors from using strict/warnings and now your script seems to work (see below). If I were you, I'd still go back and rename some variables to make your script easier to expand/maintain/troubleshoot in the future.

Where does the user get the values that are being typed in manually? Wouldn't it be easier and more reliable for the user to store these values in a simple little text file? It would be very easy to make your script read from a file instead of the keyboard. (If the user is reading these numbers from some other data file, it would be even better for the script to read that data file, instead of making the user type the values manually while your script is running.)

Reading input from a file will make it a lot easier to debug (and easier to ask for help: show the input to the script, and tell us what you'd like to see as output for the given input). For testing purposes, you can even included test data as part of the source code file. Here's an example of a script that allows the user to name a file on the command line, but if no file name is given, it reads sample data from the source code file itself: