Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: perl6 matrix arrayof arrays

by mr_ron (Chaplain)
on Mar 22, 2018 at 13:24 UTC ( #1211523=note: print w/replies, xml ) Need Help??

in reply to perl6 matrix arrayof arrays

cannot use @arr[0].elems : gives an error

Like @arr vs $#arr in Perl, I'm guessing @arr[0].elems was causing warnings for accessing the element just after the end of an array.

A possible alternative coding:

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 for @arr { say ( .map: {.fmt: "%7.1f\t"} ).join } say "=======\t" x @arr[0].elems; say ( (0..@arr[0].end).map: {@arr[*; $_].sum.fmt("%7.1f\t")} ).join; #say ( ([Z] @arr).map: { .sum.fmt("%7.1f\t") } ).join;

Replies are listed 'Best First'.
Re^2: perl6 matrix arrayof arrays
by Anonymous Monk on Mar 22, 2018 at 14:31 UTC
    hello Ron

    Thanks for you're reply. As i said : just starting with perl6.
    Learning from the docs is not easy. But what you showed me was easy to understand

    wanted to use the + in calculating the totals of each column. The way with sum is new to me.
    Thanks for showing this option to do it an other way..

      Since you describe the "docs" as "not easy", I am concerned that you are only looking at and not also looking at the tutorial level information at Have you looked at tutorials or introductory books?

      A review of the tutorials led me to refine:

      for @arr { say ( .map: {.fmt: "%7.1f\t"} ).join }
      to be
      for @arr { say ($_>>.fmt: "%7.1f\t" ).join }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1211523]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-12-04 19:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found