http://www.perlmonks.org?node_id=1004615

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?
#!/usr/bin/perl -w use bignum; # pseudocode # print "Enter number of counts" # $ct = <>; # @arr = (); # for ($i = 0; $i < $ct; $i++) { # each iteration of loop calls subroutine # to get cell counts from user and stores in variable # push() variable to store in array # $count_i = &indiv_count() # push (@arr, $count_i); # } # output @arr # $arr_len = @arr; # print "The counts were:\n"; # for ($j = 0; $j< $arr_len; $j++) { # print "Count number $j was arr[$j]\n"; # } print "Enter number of counts.\n->"; my $ct = <>; chomp $ct; print "\n$ct"; @arr = (); for ($i = 0; $i < $ct; $i++) { my $count_i = &indiv_count(); push (@arr, $count_i); } $arr_len = @arr; print "The counts were:\n"; for ($j = 0; $j< $arr_len; $j++) { print "Count number $j was $arr[$j]\n"; } sub indiv_count { my ($input); print "Enter individual count from scope. Press Enter without inp +ut to end list\n"; @scope_ct = (); while ($input = <STDIN>) { chomp $input; last if ($input =~ /^\s*$/); push (@scope_ct, $input); } my $scope_ct = @scope_ct; for ($i=0; $i<$scope_ct; $i++){ $cell_sum += pop(@scope_ct); } $cell_ct = (($cell_sum/$scope_ct)/0.0000015); return $cell_ct; }