creating/using libraries Perl...blank outout?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting creating/using libraries Perl...blank outout?
# 1  
Old 04-26-2010
creating/using libraries Perl...blank outout?

Good morning!!

Im trying to create a script that should get a list of numbers from the user (using STDIN or a list of arguments), and call my library function.
Code:
#!use/bin/perl

require 'my-lib.pl';
@userArray = <STDIN>;

while()
{
chomp;
last if ! /\d/;
push(@userArray,&_);
}
($sum,$avg) = $sumIt(@userArray);

print "Total:$sum\nAverage\n:$avg\n";

Im my library it should contain a function that takes in an array of numbers, then the function will calculate the average of the numbers, the total of the numbers and a new array of numbers which is divided by 2. The new list will contain all this information.

My library:
Code:
sub sumIt {
my @functionArray = @_;
forwach my $line(@functionArray){
$functionSum += $line;
$count++
}
return ($sunctionSum,$functionSum / $count);
}
1:

But it doesnt return anything to help me. No errors, nothing. It appears to hang?

Any help with this will be greatly appreciated!
Bigben

Last edited by Franklin52; 04-26-2010 at 04:00 AM.. Reason: Please use code tags!
# 2  
Old 04-26-2010
Is this a typo?
Code:
forwach my $line(@functionArray)

# 3  
Old 04-26-2010
Yes it is a typo....sorry its foreach.

That typo is not in my code though. Thanks for catching it fraklin!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies

2. Shell Programming and Scripting

Bc in shell script is creating blank files

Hi, I am creating a shell script which will check the processing of the main script if the error count is more than 2% of the record count in a feed. Part of the code is below: err_tol=`echo $feed_cnt \* 0.02 |bc` while read line do err_cnt=$(grep -i "$line" $err_log | wc -l) ... (5 Replies)
Discussion started by: member2014
5 Replies

3. Shell Programming and Scripting

awk to indent file outout

i have a file that contains information such as this: hostname.sky.net === 12.39.59.35 hostname.sky.net === 12.39.59.35 hostname.sky.net === 12.39.59.35 hostname-newyork.sky.net ==== 13.45.35.24 hostname-newyork.sky.net ==== 13.45.35.24... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

Replicating jobs, renaming outout

Can anyone tell me if it's possible to write a script that will repeat the same job several times but give the output a slightly different name each time (i.e. change or add a number at the end of the output file)? Here is the script I use to run a single job: #!/bin/bash #PBS -N job0 #PBS -l... (1 Reply)
Discussion started by: peterjb100
1 Replies

5. UNIX for Dummies Questions & Answers

Creating a blank string of a specified size

I want to have a string which has n blank spaces For example set N = 3 create str = " " So the length depends on the value of N. I am in tcsh. (4 Replies)
Discussion started by: kristinu
4 Replies

6. Shell Programming and Scripting

getting requestName from xml outout in log file

hi all, i was wondering if there is an easy and smart way of greping for requestname (in bold below) from xml output from application log file on a solaris 10 system. The requestName is the actual method name which gets called e.g it could be 'getAccount' or getId or getAddress etc etc ... (1 Reply)
Discussion started by: cesarNZ
1 Replies

7. Shell Programming and Scripting

using libraries with Perl..getting blank output

Good morning!! Im trying to create a script that should get a list of numbers from the user (using STDIN or a list of arguments), and call my library function. My script: #!use/bin/perl require 'my-lib.pl'; @userArray = <STDIN>; while() { chomp; last if ! /\d/;... (1 Reply)
Discussion started by: bigben1220
1 Replies

8. Shell Programming and Scripting

Count uncommented, blank and source lines in perl

Hi friends, I am working on a perl script to count the commented lines, blank lines and source lines separately. Let me know if you have one. For example i have a file containing the lines: /** * SOURCE CODE */ public class SessionConstants { /** * Code for Session created */... (4 Replies)
Discussion started by: nmattam
4 Replies

9. Shell Programming and Scripting

Blank space cause error when use perl

I write a script with register and login user. So, i encrypt password with encryptedpass=`perl -e "print crypt("${mypass}",salt)"` if password do not contain blank space, it work but if password have blank space, it cause error in that line the error is: syntax error at -e ..... Anyone... (3 Replies)
Discussion started by: WuZun
3 Replies

10. Shell Programming and Scripting

blank line deletion in a file using perl

Dear All, I am looking for an option in perl using which i could delete empty lines in a file. Or the alternative of sed '/^$/d' <filename> in perl. Sed is not working in my perl script :( Pls help me out . Thanks, VG (4 Replies)
Discussion started by: vguleria
4 Replies
Login or Register to Ask a Question