Raul Ruiz Jr. wrote:
I am taking an online ceu course in scripting with Unix. I have been
stumped by this project. Can anyone out there help me out a bit. I
created a script at the bottom and it does not quite work. What am I
missing?

perldoc -q "How do I do .anything.?"

I know I am missing some thing but this is my first time working with
perl. I know it will take me a while to get good at it but so far its
been fun. I would appreciate the help if possible. Here is my project and below is my code. Write a script called obj.pl and a library called obj-lib.pl. The
library should contain a function that takes in an array of numbers
(of arbitrary size).

perldoc perlsub

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 comprised of the other numbers divided by 2.
It will then return a new list with all of that information.

So you have to return *three* things.

The script file, obj.pl should get a list of numbers from the user
(either via STDIN or a list of arguments) and call the library

The list of arguments is stored in the @ARGV array.

perldoc perlvar

function.
Here is my script to solve the project. #!/usr/bin/perl

You should probably start your program with the warnings and strict pragmas to help you find common mistakes.

use warnings;
use strict;

require 'lib.pl';

@userArray = <STDIN>;

$sum = sumIt(@userArray);

You are supposed to return *three* things.

print $sum;

#_END_
And then for my library:

sub sumIt(){

Your prototype says that sumIt does not accept any arguments. You shouldn't use prototypes.

perldoc perlsub

   @functionArray = @_;
   foreach $line(@functionArray){
   $functionSum += $line;
   }
   return $functionSum;

Where is "the average of the numbers" and "a new array of numbers which is comprised of the other numbers divided by 2"?

}

1;


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

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


Reply via email to