Started with perl6 shortly.. perl5 has AoA ... wanted to know if something can be done in perl6...
It seems that it can be done using perl6 :
C:\WINDOWS\system32>perl6 -v This is Rakudo Star version 2018.01 built on MoarVM version 2018.01 implementing Perl 6.c.
So here is the code which works under windows10
use v6; my @arr = [ [ 1.1,2.2,3.3,4.4,5.5 ], [ 10,20,30,40,50 ], [ 100,200,300,400,500 ], [ 1000,2000,3000,4000,5000 ], ]; dd @arr; # dump the matrix loop ( my $row=0; $row <= @arr.end; $row++) { #say "Idx : $row"; loop (my $col=0 ; $col <= @arr[$row].end ; $col++ ) { print "@arr[$row][$col].fmt("%7.1f")\t"; } print "\n"; } my $aant_cols = ( @arr[0].end ) ; # It's a matrix : so Just take one +row to find out the number of columns # cannot use @arr[0].elems : gives +an error print "=======\t" x $aant_cols + 1 , "\n"; loop ( my $col=0 ; $col <= $aant_cols ; $col++ ) { printf "%7.1f" , [+] @arr[*;$col] ; # calculate the total for each + column print "\t" } say "";
The above creates the following result
Array @arr = [1.1, 2.2, 3.3, 4.4, 5.5, 10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000, 2000, 3000, 4000, 5000] 1.1 2.2 3.3 4.4 5.5 10.0 20.0 30.0 40.0 50.0 100.0 200.0 300.0 400.0 500.0 1000.0 2000.0 3000.0 4000.0 5000.0 ======= ======= ======= ======= ======= 1111.1 2222.2 3333.3 4444.4 5555.5
Please notice : All columns are totalled ( =sum in excel ) .
Could not find any usefull examples in the perl6 documentation. So I learned it myself.
Hope it's of use for sombody else
Have fun with perl6
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perl6 matrix arrayof arrays
by mr_ron (Chaplain) on Mar 22, 2018 at 13:24 UTC | |
by Anonymous Monk on Mar 22, 2018 at 14:31 UTC | |
by mr_ron (Chaplain) on Mar 22, 2018 at 19:13 UTC | |
Re: perl6 matrix arrayof arrays
by b2gills (Novice) on Mar 28, 2018 at 16:31 UTC |
Back to
Cool Uses for Perl