Perl Scripting issue - homework

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    Here is the problem:
    Lesson 13 OBJ1: OST Class online.

Write a script called obj13-1.pl and a library called obj13-lib.pl.

1- The library should contain a function that takes in an array of numbers (of arbitrary size).
2- 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.

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.

  1. Relevant commands, code, scripts, algorithms:

  2. The attempts at a solution (include all code and scripts):
    My attempt at this, remember I'm a newbie to unix/linux:

    Obj13-1.pl

  #!�usr/bin/perl
  require �obj13-lib.pl�;
   
  @userarray = <STDIN>;
  $sum = sumIt(@userarray);
  $ave = $sum/(@userarray);
   
  print�Total: $sum\n�;
  print�Average: $ave\n�;
   
  foreach((@userarray)/2){      THIS PART IS WRONG yes I need a foreach loop to draw out the input numbers, but (@userarray)/2) isn't working. 

  print�Divided by 2: @userarray\n�;
  }
   
  #_END_
   

Obj13-lib.pl

  Sub sumIt{
         @functionarray = @_;
         foreach $line(@functionarray){
         $functionsum += $line;
          }
           return $funtionsum;
  }
   
  1;
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    OST OReilly School of Technology, Online course, USA, Kelly Hoover instructor. Course is Unix/Linux administration.

Tried to post this and got this msg: So I'm taking the link to my class out.

  1. "You are only allowed to post URLs once you have at least 5 posts"

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Obj13-1.pl

  #!/usr/bin/perl
  require �obj13t-lib.pl�;
  
  @userarray = <STDIN>;
  $sum = sumIt(@userarray);
  $ave = $sum/(@userarray);
  $newline = @newaray;
  
  print�Total: $sum\n�;
  print�Average: $ave\n�;
  print�New Array Div by 2: @newarray\n�;
  
  #_END_

obj13-lib.pl

  sub sumIt{
         my @functionarray = @_;
         my $functionsum = 0;
         my $newline = 0;
  
  foreach my $line(@userarray){
     $functionsum += $line;
     $newline = $line/2;
     push(@newarray,$newline);     
     }
     return ($functionsum);
     }
    1;

Actually you've broken the spec there, your imported function from the library file should return an array with all the calculations performed, ie you should be able to call it thus

my ($average, $total, @halves) = imported_calculation_function(@ARGV);

You could create the array of halves as you loop through the array and calculate the average afterwards.
For bonus points, check for an empty array so as to avoid a divide by zero error and also ensure all elements of the array you send to the function are numeric.
Returning an array reference for the @halves array wins you another bonus, no effect here, but it's better practice as it makes the function extensible and the first assignment to an array swallows all subsequent return values.