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.

#!/usr/bin/env perl use strict; use warnings; 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"; my @arr = (); for ( my $i = 0 ; $i < $ct ; $i++ ) { my $count_i = &indiv_count(); push( @arr, $count_i ); } my $arr_len = @arr; print "The counts were:\n"; for ( my $j = 0 ; $j < $arr_len ; $j++ ) { my $iteration = $j + 1; print "Count number $iteration was $arr[$j]\n"; } sub indiv_count { my ($input); print "Enter individual count from scope. Press Enter without inp +ut to end list\n"; my @scope_ct = (); while ( $input = <STDIN> ) { chomp $input; last if ( $input =~ /^\s*$/ ); push( @scope_ct, $input ); } my $cell_sum; my $scope_ct = @scope_ct; for ( my $i = 0 ; $i < $scope_ct ; $i++ ) { $cell_sum += pop(@scope_ct); } my $cell_ct = ( ( $cell_sum / $scope_ct ) / 0.0000015 ); return $cell_ct; } __END__ $ ./cell_counter.pl Enter number of counts. ->3 3Enter individual count from scope. Press Enter without input to end +list 1 2 3 Enter individual count from scope. Press Enter without input to end l +ist 4 5 6 Enter individual count from scope. Press Enter without input to end l +ist 7 8 9 10 The counts were: Count number 1 was 1333333.333333333333333333333333333333333 Count number 2 was 3333333.333333333333333333333333333333333 Count number 3 was 5666666.666666666666666666666666666666667

In reply to Re: Bug in code by frozenwithjoy
in thread Bug in code by disulfidebond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.