Perl calculate average from randomly populated array
<p>I have a school assignment I need help with. Now, I know what you're thinking, but my teacher is out of town and hasn't answered my e-mails, and my other classmates have no clue how to solve this problem. A few pointers and tips would be greatly appreciated!</p>

<p>The assignment is this:</p>

<p>We're supposed to create an array, populate it with 20 to 30 random integers in the range of 1-100. Then, by the help of subroutines, we're supposed to calculate the average of these numbers.</p>

<p>The problem occurs when I'm calling the subroutine back, which gives me either answer 0 or the "Illegal division by 0" error. The code I have right now is this:</p>

<pre><code>#! /usr/bin/perl -w

use warnings;
use strict;

# Declaring the scalar variables and arrays.
my @AllNumbers;

# Create random data set of between 20 to 30 measures used for the 100 random intigers.
my $random_number = int( rand( 31 - 20 ) ) + 20;

# Create random data set of 100 intigers.
for ( my $i = 0 ; $i &lt;= $random_number ; $i++ ) {
    $AllNumbers[$i] = int( rand( 100 - 1 ) );
}

# Print the 20 to 30 random numbers (range 1 - 100).
print("Your random numbers are: \n@AllNumbers");

sub average {
    my $ArrayAverage = @_;
    for (@_) {
        my $total += $_;
    }
    return $ArrayAverage / $random_number;
} ## end sub average

# Print the mean/average of the 20-30 numbers.
print( "\n\nThe average of those random numbers is: ", &amp;average, "\n\n" );
</code></pre>

<p>Now, as I said, I'd like to solve this problem myself, and I've spent an entire two days with this, but can't seem to solve it no matter what I do. Any tips would be greatly appreciated. P.S. It should be mentioned that we're not supposed to use any modules/plugins.</p>