in reply to Re: Finding average using package subroutine
in thread Finding average using package subroutine

I'm sort of teaching myself perl and have a similar problem. I used the problem above but I'm not getting the same results. I want to find the average using a <STDIN> and subroutines.

here's what I've got:

sub:

sub avg {
$n = 0;
@array = (<STDIN>);


$total =$#array + 1;

foreach $array ( @array ) {
$n += $array;
}
$res = $n/$total;
return $res;
}

1;

function:
#!/usr/bin/perl

require 'obj13-lib.pl';

$res = avg();
print $res;

Where am I going wrong?
  • Comment on Re^2: Finding average using package subroutine

Replies are listed 'Best First'.
Re^3: Finding average using package subroutine
by toolic (Bishop) on Aug 09, 2011 at 16:50 UTC