Hi , i did not understand the obj13-lib.pl part and second thing is,i am also new to perl....The following code gives you the sum,avg and the new array..i am taking the input directly from the command line for the first 10 nums... Hope this helps..If not..then i will also be looking at the replies....cheers!!! The code is :
#!/usr/bin/perl -w use strict; my $outfile="numberlist.pl"; open (OUT,">$outfile") || die "unable to open $outfile: $!"; my $count=0; while ($count != 10) { $count++; my $line =<STDIN>; print OUT "$line"; } close(OUT); open (IN,"<$outfile") || die "unable to open $outfile: $!"; my @fred=<IN>; my $sum =0; my @newarray =(); foreach my $num (@fred) { $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); On Jul 19, 3:22 pm, [EMAIL PROTECTED] (Amichai Teumim) wrote: > Hi > > This is my homework: > > "Write a script called *obj13-1.pl* and a library called *obj13-lib.pl*. The > library should contain a function that takes in an array of numbers (of > arbitrary size). 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 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." > > I don't even know where to start. > > Ok so I have a script names obj13-1.pl and a library called obj13-lib.pl. So > for the array I could do: @numbers = 1,2,3,4,5,6,7,8,9,10 (right?) > > I'm not sure how to use perl to calculate. How on earth would I go about > calculating the average of these numbers? > > I don't get why I even need a library for this, because what do I even put > in the obj13-1.pl. All this is in the library! Or I am totally not getting > this? > > Thanks for your assistance > > Amichai -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/