For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > library (random numbers)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author library (random numbers)
Amichai Teumim

2007-08-07, 7:59 am

Does this make any sense?

Here is the script again:

#!/usr/bin/perl

use strict;
use warnings;

require 'obj13-lib.pl';

my @userArray = <STDIN>;

my $sum = sumIt(@userArray);

print $sum;


And here is the library:

sub sumIt{
my $total;
$total += $_ for @_;
warn "@_ was empty, total undefined!\n" if !defined $total;
}

sub avg(@)
{
my @arr = @_;
my $arrSize = scalar(@arr);
#(last index). Double check;

my $sum = sumIt(@userArray);

return sumIt(@arr) / @sum;
}

1;


Does the library make sense?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com