Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Perl confusion

by stamp1982 (Novice)
on Jun 26, 2013 at 21:03 UTC ( [id://1040842]=perlquestion: print w/replies, xml ) Need Help??

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: Perl confusion
by Ralesk (Pilgrim) on Jun 26, 2013 at 21:13 UTC
      Ralesk, I would be able to perform for each loop, print average and split. My real confusion is how to obtain the sequence length separated by white space in perl and that is what I need clarification on. Thanks!
Re: Perl confusion
by kcott (Archbishop) on Jun 27, 2013 at 08:29 UTC
Re: Perl confusion
by 5mi11er (Deacon) on Jun 26, 2013 at 21:16 UTC
    This isn't the place to get homework done for you. We expect you to try it on your own, and then when you're stuck with some specific problem, we'll typically help you through that one issue. There's lots of perl on the net, google around find something close, cobble it together to try to accomplish your task, and google through the simple issues. Then come back with code and ask a specific question about why it does something you didn't expect, or doesn't do what you did expect.

    -Scott

      Scot, Thanks for your message. I did not want a solution to the problem but a breakdown of what was expected in a beginners terms. I know to obtain user input I have to use STDIN but how to write that obtain that with the whitespace is where my confusion lies and I would appreciate some explanation. It is not my homework just practicing Perl for beginners. Please what does the sequence length mean? Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found