using libraries with Perl..getting blank output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using libraries with Perl..getting blank output
# 1  
Old 04-26-2010
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:

[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";[code1]

In 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 = @_;
foreach my $line(@functionArray){
$functionSum += $line;
$count++
}
return ($functionSum,$functionSum / $count);
}
1:[code1]

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

Any help with this will be greatly appreciated!
Bigben
# 2  
Old 04-27-2010
you should not call your function as $function, call it as simply function.

And enable warnings, and strict as, for debugging.,
Code:
use strict;
use warning;

for better debugging, use
Code:
use diagnostics;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command is saving output as blank file

Hi, I am working on a script where I am adding adding colors to few of the info in the output. Now , after that is done , I see colour codes in log files which I don't want to see.:mad::mad::mad::mad: So , I tried using sed command in script as below which gives me o/p (new.log) as blank file... (7 Replies)
Discussion started by: Dream4649
7 Replies

2. Shell Programming and Scripting

Perl : blank lines are displayed in the output after deleting few rows from excel

I am working on an assignment to pull all the records from excel sheet programatically and use the data for further calculations. In this process, I first defined 10 records in excel sheet and executed the below code. In the first run it is OK. But after deleting last few rows in excel sheet and... (0 Replies)
Discussion started by: giridhar276
0 Replies

3. Shell Programming and Scripting

Blank line in command output

My script ssh's to another server and gathers information then process them. The problem is that the output of a command has an unwanted "blank lines". ... ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk '{print $5}' > ${DATAFILE} ... $ cat ${DATAFILE} 123456789 (There's a blank... (7 Replies)
Discussion started by: pdtak
7 Replies

4. Shell Programming and Scripting

Blank as variable/output when run from command line

When I run this: PDHDURL=`/usr/bin/curl --silent http://www.phdcomics.com/comics.php | /usr/bin/grep -o http://www.phdcomics.com/comics/archive/.*.gif | head -1` echo -e "$PHDURL" It is totally blank. However, when I just run it from the terminal: /usr/bin/curl --silent... (2 Replies)
Discussion started by: killer54291
2 Replies

5. Shell Programming and Scripting

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. #!use/bin/perl require 'my-lib.pl'; @userArray = <STDIN>; while() { chomp; last if ! /\d/; push(@userArray,&_); }... (2 Replies)
Discussion started by: bigben1220
2 Replies

6. 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

7. Shell Programming and Scripting

Script not running from cron it gives blank output

Hi, I have ascript which drops a mail with the jobs status. here is the script: #!/bin/ksh mypath=/home/gaddamja flashlogpath=/sbcimp/dyn/data/flash/log cd $mypath v1=`ls -lrt | grep -i checkFilesForAmber_EUR1. |tail -1 | awk '{print $8}'` v2=`cat $v1` cd $flashlogpath ... (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

8. Shell Programming and Scripting

PERL: removing blank lines from multiple files

Hi Guru's , I have a whole bunch of files in /var/tmp that i need to strip any blank lines from, so ive written the following script to identify the lines (which works perfectly).. but i wanted to know, how can I actually strip the identified lines from the actual source files ?? my... (11 Replies)
Discussion started by: hcclnoodles
11 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