stamp1982 has asked for the wisdom of the Perl Monks concerning the following question:
Ask the user for a list of sequence lengths, separated by whitespace (Example: 100 123 45 …etc.). The sequence lengths will be stored in a string called $input. a. Split the String $input and create an array. b. Use the foreach loop to get the sum of all sequence lengths. c. Print the average. this is what I have now: but I don't get the space at the print command.
use strict; use warnings; my $i = 0; my $input = ""; while ($i < 3) { chomp(my $num = <>); $input .= $num . "". $num; $i++; } print "Total input is $input\n"; my @nums = split(' ', $input); foreach (@nums) { my $sum += $_; } print my $sum / @nums . "\n"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Diagnose code
by Loops (Curate) on Jun 27, 2013 at 02:17 UTC | |
|
Re: Diagnose code
by Athanasius (Archbishop) on Jun 27, 2013 at 02:13 UTC |