Sponsored Content
Homework and Emergencies Homework & Coursework Questions Perl Scripting issue - homework Post 302521274 by valhalla on Tuesday 10th of May 2011 06:06:08 PM
Old 05-10-2011
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.

2. Relevant commands, code, scripts, algorithms:



3. 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
Code:
  #!’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
Code:
  Sub sumIt{
         @functionarray = @_;
         foreach $line(@functionarray){
         $functionsum += $line;
          }
           return $funtionsum;
  }
   
  1;


4. 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).

Last edited by pludi; 05-11-2011 at 04:04 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help with Perl Scripting Issue.

The Perl script runs fine without any error from command line. The script executes an external command and prints the output on a web page. But somehow when I call it from URL it does not work. Any help will be appreciated. Here is the script: --test.pl #!/usr/bin/perl # use warnings; use... (23 Replies)
Discussion started by: manik112
23 Replies

2. Shell Programming and Scripting

Unix Scripting Question (Homework)

Hello im currently taking up Operating Systems and we're on unix ryt now. we have to make a script and here are the requirements.. can someone please help me. I would reli appreciate it.. because i dont reli know how to make scripts yet. Name of script : parkingcharge.sh Create a script that... (1 Reply)
Discussion started by: pitdark
1 Replies

3. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

4. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

5. Shell Programming and Scripting

perl (homework)

------------------------------------------------------------------ -----------------------------------------------------------------? (1 Reply)
Discussion started by: Ame
1 Replies

6. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

7. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

8. UNIX for Dummies Questions & Answers

Scripting issue

Hi experts... I am really new to this scripting, i really need your help. I have this script to read and print the report, however the script does not pickup the correct hostname (eg. Svtns11d).. The script will start reading/pick up on the second line instead of reading the first line.... (1 Reply)
Discussion started by: talkhard154
1 Replies

9. Shell Programming and Scripting

Scripting issue

Hi Experts, I'm stuck with a single liner bash script. Need your help to fix it. Let me brief you that what is my expectations from this script. I need the interfaces configured for a list of servers, their respective IP address and FQDN in a output file. The output should be in the same... (3 Replies)
Discussion started by: arun_adm
3 Replies

10. UNIX for Beginners Questions & Answers

Scripting Homework, need help

Hi I just started scripting in my Unix class, but can't understand it and have trouble with homework. This is my homework: Dean needs a daily written report of the status of his Unix computer. He wants to obtain certain information about users and processes that are only accessible by executing... (1 Reply)
Discussion started by: arbogastcarl
1 Replies
Dancer::Template::TemplateToolkit(3pm)			User Contributed Perl Documentation		    Dancer::Template::TemplateToolkit(3pm)

NAME
Dancer::Template::TemplateToolkit - Template Toolkit wrapper for Dancer DESCRIPTION
This class is an interface between Dancer's template engine abstraction layer and the Template module. This template engine is recomended for production purposes, but depends on the Template module. In order to use this engine, use the template setting: template: template_toolkit This can be done in your config.yml file or directly in your app code with the set keyword. Note that by default, Dancer configures the Template::Toolkit engine to use <% %> brackets instead of its default [% %] brackets. This can be changed within your config file - for example: template: template_toolkit engines: template_toolkit: start_tag: '[%' stop_tag: '%]' You can also add any options you would normally add to the Template module's initialization. You could, for instance, enable saving the compiled templates: engines: template_toolkit: COMPILE_DIR: 'caches/templates' COMPILE_EXT: '.ttc' By default, Template is used, but you can configure Dancer to use a subclass with the "subclass" option. engines: template_toolkit: subclass: My::Template WRAPPER, META variables, SETs Dancer already provides a WRAPPER-like ability, which we call a "layout". The reason we do not use TT's WRAPPER (which also makes it incompatible with it) is because not all template systems support it. Actually, most don't. However, you might want to use it, and be able to define META variables and regular Template::Toolkit variables. These few steps will get you there: o Disable the layout in Dancer You can do this by simply commenting (or removing) the "layout" configuration in the config.yml file. o Use Template Toolkit template engine Change the configuration of the template to Template Toolkit: # in config.yml template: "template_toolkit" o Tell the Template Toolkit engine who's your wrapper # in config.yml # ... engines: template_toolkit: WRAPPER: layouts/main.tt Done! Everything will work fine out of the box, including variables and META variables. SEE ALSO
Dancer, Template AUTHOR
This module has been written by Alexis Sukrieh LICENSE
This module is free software and is released under the same terms as Perl itself. perl v5.14.2 2012-01-27 Dancer::Template::TemplateToolkit(3pm)
All times are GMT -4. The time now is 02:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy