Re: I need array of hashes help

2019-12-03 Thread ToddAndMargo via perl6-users



On 2019-12-03 03:17, Fernando Santagata wrote:


You can't write "my @y[0]".





--
Fernando Santagata


Hi Fernando,

You called it.  I had to declare @y first before
assigning hashes to it.

Thank you!

-T

$ p6 'my @y[0]={a=>"aa",b=>"bb"};'
Illegal dimension in shape: 0. All dimensions must be integers bigger than 0
  in block  at -e line 1


$ p6 'my @y; @y[0]={a=>"aa",b=>"bb"};'



Re: I need array of hashes help

2019-12-03 Thread Fernando Santagata
Try:

p6 'my @y; @y[0]={a=>"aa",b=>"bb"}; push @y, {a=>"AA",b=>"BB"}; for @y.kv
-> $I, $J { say "Index $I  $J  $J" }; say "elements " ~ @y.elems;'

You can't write "my @y[0]".

On Tue, Dec 3, 2019 at 11:53 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2019-12-03 02:39, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > What am I doing wrong here?
> >
> > $ p6 'my @y; my %x=(a=>"aa", b=>"bb"); @y[0] = %x; %x="AA";
> > %x="BB"; push @y,{%x}; for @y.kv -> $I, $J { say "Index $I  $J
> > $J" }; say "elements " ~ @y.elems;'
> >
> > Index 0  AA  BB
> > Index 1  AA  BB
> > elements 2
> >
> >
> > It should be
> >
> > Index 0  aa  bb
> > Index 1  AA  BB
> > elements 2
> >
> >
> > Many thanks,
> > -T
>
> okay, I got this far:
>
> $ p6 'my @y; push @y, {a=>"aa",b=>"bb"}; push @y, {a=>"AA",b=>"BB"}; for
> @y.kv -> $I, $J { say "Index $I  $J  $J" }; say "elements " ~
> @y.elems;'
>
> Index 0  aa  bb
> Index 1  AA  BB
> elements 2
>
>
> But I still have to figure out how to
>
> @y[0]={a=>"aa",b=>"bb"}
>
> $ p6 'my @y[0]={a=>"aa",b=>"bb"}; push @y, {a=>"AA",b=>"BB"}; for @y.kv
> -> $I, $J { say "Index $I  $J  $J" }; say "elements " ~ @y.elems;'
> Illegal dimension in shape: 0. All dimensions must be integers bigger than
> 0
>in block  at -e line 1
>


-- 
Fernando Santagata


Re: I need array of hashes help

2019-12-03 Thread ToddAndMargo via perl6-users

On 2019-12-03 02:39, ToddAndMargo via perl6-users wrote:

Hi All,

What am I doing wrong here?

$ p6 'my @y; my %x=(a=>"aa", b=>"bb"); @y[0] = %x; %x="AA"; 
%x="BB"; push @y,{%x}; for @y.kv -> $I, $J { say "Index $I  $J 
$J" }; say "elements " ~ @y.elems;'


Index 0  AA  BB
Index 1  AA  BB
elements 2


It should be

Index 0  aa  bb
Index 1  AA  BB
elements 2


Many thanks,
-T


okay, I got this far:

$ p6 'my @y; push @y, {a=>"aa",b=>"bb"}; push @y, {a=>"AA",b=>"BB"}; for 
@y.kv -> $I, $J { say "Index $I  $J  $J" }; say "elements " ~ 
@y.elems;'


Index 0  aa  bb
Index 1  AA  BB
elements 2


But I still have to figure out how to

@y[0]={a=>"aa",b=>"bb"}

$ p6 'my @y[0]={a=>"aa",b=>"bb"}; push @y, {a=>"AA",b=>"BB"}; for @y.kv 
-> $I, $J { say "Index $I  $J  $J" }; say "elements " ~ @y.elems;'

Illegal dimension in shape: 0. All dimensions must be integers bigger than 0
  in block  at -e line 1