You've got a few issues with your code. You're re-declaring some of your variables with my incorrectly (always put use warnings; and use strict; at the top of your scripts), you're using @array in a global sense when you should be passing it into the subroutine instead, and unless you have good reason not to, you should be putting your use statements at the top of your code as it's far easier to see what the code is using.
With these changes and additions, does it do what you expect? I create the array, send it in as a list of parameters to the sub, perform actions on each element, push the result to a new array, then when done the loop, return the entire new array:
use warnings;
use strict;
use List::Util qw( min max );
my @not_normalized = qw(5 4 9 9 6);
my @normalized = normalizer(@not_normalized);
print "$_\n" for @normalized;
sub normalizer {
my @not_normalized = @_;
my $min_numarray = min @array;
my $max_numarray = max @array;
my $normalized;
my @normalized_list;
foreach my $element (@not_normalized){
my $numdiv = $element - $min_numarray;
my $numden = $max_numarray - $min_numarray;
$normalized = $numdiv / $numden;
push @normalized_list, $normalized;
}
return @normalized_list;
}
Output:
0.2
0
1
1
0.4
update: renamed arrays to have sensible names