Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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; }

In reply to 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found