in reply to returning array in custom subroutine
use strict; use warnings; my @not_normalized = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); my @normalized = normalizer(@not_normalized); print "@normalized"; sub normalizer { # to normalize an input array bw 0 and 1 my @array = @_; use List::Util qw( min max ); # import min and max module my $min_numarray = min @array; # get min of args my $max_numarray = max @array; # get max of args my $numden = $max_numarray - $min_numarray; # denominator: max tot +al - min total foreach my $index (0..$#array) { # loop over args my $numdiv = $array[$index] - $min_numarray; # numerator: n + - min total $array[$index] = $numdiv / $numden; # normalize } return @array; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: returnong array in custom subroutine
by perldigious (Priest) on Aug 31, 2016 at 14:05 UTC | |
by InfiniteSilence (Curate) on Aug 31, 2016 at 17:43 UTC | |
by perldigious (Priest) on Aug 31, 2016 at 19:16 UTC | |
by dovah (Novice) on Aug 31, 2016 at 14:09 UTC |