in reply to Re^2: Passing an array to a subroutine help?!
in thread Passing an array to a subroutine help?!

Each of your subroutines returns a value. You must capture this returned value if you want to display the results in the following print statement.

Here is your code with the small additions pointed out above

use strict; print "\n\nEnter numbers, one number per line.\nEnter a blank line whe +n all values have been entered.\n"; my @values = (); while (my $val = <>) { chomp($val); if ($val != "0") { @values = (@values, $val); } elsif ($val eq "0") { print "Please do not enter values of zero.\n"; } elsif ($val eq "") { last; } } my $arraysize = @values; print "\nYou have entered $arraysize values\n\n"; my $min = minimum(@values); my $max = maximum(@values); my $average = average(@values); print "The minimum you have entered is $min\n\n"; print "The maximum you have entered is $max\n\n"; print "The average of the numbers you entered is $average\n\n"; sub maximum { my @args = @_; my $max = $args[0]; foreach my $i (@args) { if ($i > $max) { $max = $i; } } return $max; } sub minimum { my @things = @_; my $min = $things[0]; foreach my $z (@things) { if ($z < $min) { $min = $z; } } return $min; } sub average { my @stuff = @_; my $sum = 0; ($sum += $_) for @stuff; my $average = $sum / @stuff; return $average; }

Note: Code run through Perl::Tidy to clean up the formatting