usinf STDIN or ARGV, taking the input, calling the library and printing results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usinf STDIN or ARGV, taking the input, calling the library and printing results
# 1  
Old 04-22-2010
usinf STDIN or ARGV, taking the input, calling the library and printing results

Good morning!!

I wrote a script and Im not the best at Perl so I would like someone to look it over....just in case. Ive been working on this script forever!!

The script is supposed to: Have the user enter a number using STDIN. 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 tehn return a new list with all of that information. It should be taking the input, calling the library and printing the end results.

Code:
#!/usr/bin/perl

my $outfile="numberlist.pl";

open (OUT,">$outfile") || die "can't open $outfile: $!";
my $count=0;
while ($count != 10)
{
$count++;
my $line=;
print OUT "$line";
}
close (OUT);

open (IN,"<$outfile") || die "can't open $outfile: $!";

my @ben=;

my $sum=0;
my @newarray=();
foreach my $num (@ben)
{
$sum+=$num;
my $newnum = $num /2;
my $newarray_nums=push (@newarray,$newnum);
}
print "New Array is :@newarray\n";
print "Sum :$sum\n";

my $avg = $sum /10;

print "Avg :$avg\n";

close(IN);

Sidenote-Perl makes my head hurt. I think Im struggling because it doesnt seem logical to me. ANy suggestions?

Ben

---------- Post updated at 03:02 AM ---------- Previous update was at 02:18 AM ----------

Thanks Pludi!!

---------- Post updated at 04:07 AM ---------- Previous update was at 03:02 AM ----------

Can anyone help?

Last edited by pludi; 04-22-2010 at 03:58 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in taking input Shell script

I was writing a shell script, where i need to run a command through script and then take input from user and later terminate it. i am not sure how to take input in a proper format immediately after a command. example: below command line is used to import some data in to database (LDAP)... (3 Replies)
Discussion started by: Mridul17
3 Replies

2. UNIX for Advanced & Expert Users

O argv, argv, wherefore art thou argv?

All of my machines (various open source derivatives on x86 and amd64) store argv above the stack (at a higher memory address). I am curious to learn if any systems store argv below the stack (at a lower memory address). I am particularly interested in proprietary Unices, such as Solaris, HP-UX,... (9 Replies)
Discussion started by: alister
9 Replies

3. UNIX for Dummies Questions & Answers

Taking the average of two columns and printing it on a new column

Hi, I have a space delimited text file that looks like the following: Aa 100 200 Bb 300 100 Cc X 500 Dd 600 X Basically, I want to take the average of columns 2 and 3 and print it in column 4. However if there is an X in either column 2 or 3, I want to print the non-X value. Therefore... (11 Replies)
Discussion started by: evelibertine
11 Replies

4. Shell Programming and Scripting

Suplying stdin input within script

Hi , I have script in that , i uninstall rpm using rpm -ef $rc1 now my query is rpm -ef is asking user input DO YOU Want To continue (YES/NO) for each uninstalltion. now i want to supply YES variable when it asks for above statement . so that i dont have to give user input from... (4 Replies)
Discussion started by: raghavendra.nsn
4 Replies

5. Shell Programming and Scripting

Taking one input at a time

Legends, Please help me to come out of the below Bermuda triangle. I have four inputs in a shell script: A B C D Now, If A is passed by user then, B C D will be ignored. If C is passed by user, then A B D will be ignored. Regards, Sandy (11 Replies)
Discussion started by: sdosanjh
11 Replies

6. Shell Programming and Scripting

Problem while taking input from User

Hi All, I am facing a problem while taking input from user in Shell Script. Basically , I want to read a file line by line. And I want to remove certain lines of that file.But before removing those lines , I need to ask the user whether user wants to remove the lines. If user inputs "Yes" , the... (3 Replies)
Discussion started by: swapnil.nawale
3 Replies

7. Shell Programming and Scripting

Calling C program from cron results in no output

I can call a C program from the shell and results are outputted as normal. The C program processes some files and spits out a .csv file. If I scheduled it in cron, there is no output. If their a special way to schedule C programs in cron? thanks & regards (1 Reply)
Discussion started by: hazno
1 Replies

8. UNIX for Dummies Questions & Answers

Taking a Users input to for the basis of a Grep

Hi I'm currently putting together a script that will grep a set of data for a particular input, specified by the user. I'm getting myself all tangled up with my Echo's and reads. What i'm looking to do is get it so that it prompts the user to enter a value (echo) and then uses their input... (5 Replies)
Discussion started by: Great Uncle Kip
5 Replies

9. Shell Programming and Scripting

Problem taking input from file with for loop

I am trying to take input from a file and direct it into a bash script. This script is meant to be a foreach loop. I would like the script to process each item in the list one by one and direct the output to a file. # cat 1loop #!/bin/bash # this 2>&1 to redirect STDERR & STDOUT to file... (4 Replies)
Discussion started by: bash_in_my_head
4 Replies

10. Programming

Changing stdin from file redirection to console input

Hi I am doing file redirection at console for use by my binary. %console%> bin &lt inputfile After reading in the entire file, I want my program to continue taking input from the console. So essentially I want to redirect stdin back to console. But I cant figure out how to do it. I am... (4 Replies)
Discussion started by: nauman
4 Replies
Login or Register to Ask a Question