Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Bug in code

by frozenwithjoy (Curate)
on Nov 19, 2012 at 22:18 UTC ( #1004618=note: print w/ replies, xml ) Need Help??


in reply to Bug in code

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


Comment on Re: Bug in code
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004618]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (17)
As of 2014-07-25 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls