From 73f2a2d0f35b4150d3fb5d226fa22b9cfd0af5cb Mon Sep 17 00:00:00 2001 From: dasJake Date: Sat, 27 Nov 2021 17:38:05 +0100 Subject: 140 add ch-2.pl with alternative dereferencing --- challenge-140/jake/perl/ch-2.pl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/challenge-140/jake/perl/ch-2.pl b/challenge-140/jake/perl/ch-2.pl index 830111b0c6..901d2f89e8 100644 --- a/challenge-140/jake/perl/ch-2.pl +++ b/challenge-140/jake/perl/ch-2.pl @@ -36,22 +36,19 @@ sub aggregate_multiplication_table { sub _aggregate_multiplication_table { my ( $vertical_range, $horizontal_range, $height_increment, $horizontal_values, $all_values ) = @_; - # access lists from references - my @horizontal_values = @{$horizontal_values // []}; - my @all_values = @{$all_values // []}; - # once all lines of the table have been written we can return @all_values - return \@all_values if $height_increment > $vertical_range; + #push @$all_values,; + return \@$all_values if $height_increment > $vertical_range; # we 'write' the first line of the multiplication table. # after that we run over each value in this first adding each new value to the accumulator @all_values. # we will repeat this for every line that needs to be added to the table. - @horizontal_values = 1 ... $horizontal_range; - foreach ( @horizontal_values ) { - push @all_values, $_ * $height_increment; + @$horizontal_values = 1 ... $horizontal_range; + foreach ( @$horizontal_values ) { + push @$all_values, $_ * $height_increment; } # we need to increase our line counter upon iteration. # this is necessary for our foreach loop to add the next line in the following iteration. - return _aggregate_multiplication_table ( $vertical_range, $horizontal_range, $height_increment + 1, \@horizontal_values, \@all_values ); + return _aggregate_multiplication_table ( $vertical_range, $horizontal_range, $height_increment + 1, \@$horizontal_values, \@$all_values ); } \ No newline at end of file -- cgit