On 7/19/07, Amichai Teumim <[EMAIL PROTECTED]> wrote:
Hi

This is my homework:

This really isn't a forum for people's homework.


"Write a script called *obj13-1.pl* and a library called *obj13-lib.pl*. The
library should contain a function that takes in an array of numbers (of
arbitrary size). The function will then calculate the average of the
numbers, the total of all of the numbers added together, and a new array of
numbers which is the other numbers divided by 2. It will then return a new
list with all of that information.

The script file, *obj13-1.pl* should get a list of numbers from the user
(either via STDIN or a list of arguments) and call the library function."

I don't even know where to start.

Ok so I have a script names obj13-1.pl and a library called obj13-lib.pl. So
for the array I could do: @numbers = 1,2,3,4,5,6,7,8,9,10 (right?)

No, your requirements state you must read the numbers from STDIN.  I
would suggest you start looking in perldoc perlop and perldoc perlfunc
for operators that read from files (since STDIN is just a special
file).


I'm not sure how to use perl to calculate. How on earth would I go about
calculating the average of these numbers?


Perl provides a good set of numeric operators, you should try reading
about them in perldoc perlop.  As for how to take an average of a set
of numbers, most likely they want the simple average or mean.  This is
an incredibly simple formula.  You can read more about it here:
http://en.wikipedia.org/wiki/Arithmetic_mean

I don't get why I even need a library for this, because what do I even put
in the obj13-1.pl. All this is in the library! Or I am totally not getting
this?

Often homework has you do things that are more complex than they need
to be to highlight some feature.  In this case you are supposed to be
learning about how modules work, although I am surprised that your
teacher or book wants the library to be named obj13-lib.pl.  This is a
very old way of naming perl modules (from back in Perl 4 or earlier).
Modern Perl modules are named with a .pm extension and by convention
start with an uppercase letter (unless it affects the way the
interpreter behaves, in which case it is all lowercase, think
strict.pm).


Thanks for your assistance

Amichai


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to