in reply to Diagnose code

Hello stamp1982,

You should provide a prompt to alert the user that input is required. For example: print "Enter a list of sequence lengths, separated by whitespace:\n";. And this line: $input .= $num . "". $num; is wrong; it should be something like $input .= $num . " ";. Also, to split on whitespace, you should use split(/\s+/, $input);. See split.

But the main problem arises from your repeated declarations of the $sum variable. my is used to declare and initialise a lexical variable (and if no initialisation is given explicitly, a scalar variable is by default initialised to undef). So the final few lines should be:

print "Total input is: $input\n"; my @nums = split(/\s+/, $input); my $sum; $sum += $_ for @nums; print $sum / @nums . "\n";

Note that $sum is here declared (and initialised) once only. Any further use of my on $sum would create a new variable with the same name, which is not what you want. See e.g. Variable scoping.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,