I need array of hashes help

Hi All,

What am I doing wrong here?

$ p6 'my @y; my %x=(a=>"aa", b=>"bb"); @y[0] = %x; %x<a>="AA"; 
%x<b>="BB"; push @y,{%x}; for @y.kv -> $I, $J { say "Index $I  $J<a> 
$J<b>" }; 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
0
perl6
12/3/2019 10:39:57 AM
perl.perl6.users 1262 articles. 0 followers. Follow

3 Replies
4 Views

Similar Articles

[PageSpeed] 27

On 2019-12-03 02:39, ToddAndMargo via perl6-users wrote:
> Hi All,
>=20
> What am I doing wrong here?
>=20
> $ p6 'my @y; my %x=3D(a=3D>"aa", b=3D>"bb"); @y[0] =3D %x; %x<a>=3D"AA"=
;=20
> %x<b>=3D"BB"; push @y,{%x}; for @y.kv -> $I, $J { say "Index $I=C2=A0 $=
J<a>=20
> $J<b>" }; say "elements " ~ @y.elems;'
>=20
> Index 0=C2=A0 AA=C2=A0 BB
> Index 1=C2=A0 AA=C2=A0 BB
> elements 2
>=20
>=20
> It should be
>=20
> Index 0=C2=A0 aa=C2=A0 bb
> Index 1=C2=A0 AA=C2=A0 BB
> elements 2
>=20
>=20
> Many thanks,
> -T

okay, I got this far:

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

Index 0  aa  bb
Index 1  AA  BB
elements 2


But I still have to figure out how to

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

$ p6 'my @y[0]=3D{a=3D>"aa",b=3D>"bb"}; push @y, {a=3D>"AA",b=3D>"BB"}; f=
or @y.kv=20
-> $I, $J { say "Index $I  $J<a>  $J<b>" }; say "elements " ~ @y.elems;'
Illegal dimension in shape: 0. All dimensions must be integers bigger tha=
n 0
   in block <unit> at -e line 1
0
perl6
12/3/2019 10:49:36 AM
--0000000000009269fd0598cad772
Content-Type: text/plain; charset="UTF-8"

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<a>  $J<b>" }; 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-users@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<a>="AA";
> > %x<b>="BB"; push @y,{%x}; for @y.kv -> $I, $J { say "Index $I  $J<a>
> > $J<b>" }; 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<a>  $J<b>" }; 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<a>  $J<b>" }; say "elements " ~ @y.elems;'
> Illegal dimension in shape: 0. All dimensions must be integers bigger than
> 0
>    in block <unit> at -e line 1
>


-- 
Fernando Santagata

--0000000000009269fd0598cad772
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"color:#000000">Try:<=
/div><div class=3D"gmail_default" style=3D"color:#000000"><br></div><div cl=
ass=3D"gmail_default" style=3D"color:#000000">p6 &#39;my @y; @y[0]=3D{a=3D&=
gt;&quot;aa&quot;,b=3D&gt;&quot;bb&quot;}; push @y, {a=3D&gt;&quot;AA&quot;=
,b=3D&gt;&quot;BB&quot;}; for @y.kv -&gt; $I, $J { say &quot;Index $I =C2=
=A0$J&lt;a&gt; =C2=A0$J&lt;b&gt;&quot; }; say &quot;elements &quot; ~ @y.el=
ems;&#39;</div><div class=3D"gmail_default" style=3D"color:#000000"><br></d=
iv><div class=3D"gmail_default" style=3D"color:#000000">You can&#39;t write=
 &quot;my @y[0]&quot;.<br></div></div><br><div class=3D"gmail_quote"><div d=
ir=3D"ltr" class=3D"gmail_attr">On Tue, Dec 3, 2019 at 11:53 AM ToddAndMarg=
o via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@p=
erl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef=
t:1ex">On 2019-12-03 02:39, ToddAndMargo via perl6-users wrote:<br>
&gt; Hi All,<br>
&gt; <br>
&gt; What am I doing wrong here?<br>
&gt; <br>
&gt; $ p6 &#39;my @y; my %x=3D(a=3D&gt;&quot;aa&quot;, b=3D&gt;&quot;bb&quo=
t;); @y[0] =3D %x; %x&lt;a&gt;=3D&quot;AA&quot;; <br>
&gt; %x&lt;b&gt;=3D&quot;BB&quot;; push @y,{%x}; for @y.kv -&gt; $I, $J { s=
ay &quot;Index $I=C2=A0 $J&lt;a&gt; <br>
&gt; $J&lt;b&gt;&quot; }; say &quot;elements &quot; ~ @y.elems;&#39;<br>
&gt; <br>
&gt; Index 0=C2=A0 AA=C2=A0 BB<br>
&gt; Index 1=C2=A0 AA=C2=A0 BB<br>
&gt; elements 2<br>
&gt; <br>
&gt; <br>
&gt; It should be<br>
&gt; <br>
&gt; Index 0=C2=A0 aa=C2=A0 bb<br>
&gt; Index 1=C2=A0 AA=C2=A0 BB<br>
&gt; elements 2<br>
&gt; <br>
&gt; <br>
&gt; Many thanks,<br>
&gt; -T<br>
<br>
okay, I got this far:<br>
<br>
$ p6 &#39;my @y; push @y, {a=3D&gt;&quot;aa&quot;,b=3D&gt;&quot;bb&quot;}; =
push @y, {a=3D&gt;&quot;AA&quot;,b=3D&gt;&quot;BB&quot;}; for <br>
@y.kv -&gt; $I, $J { say &quot;Index $I=C2=A0 $J&lt;a&gt;=C2=A0 $J&lt;b&gt;=
&quot; }; say &quot;elements &quot; ~ <br>
@y.elems;&#39;<br>
<br>
Index 0=C2=A0 aa=C2=A0 bb<br>
Index 1=C2=A0 AA=C2=A0 BB<br>
elements 2<br>
<br>
<br>
But I still have to figure out how to<br>
<br>
@y[0]=3D{a=3D&gt;&quot;aa&quot;,b=3D&gt;&quot;bb&quot;}<br>
<br>
$ p6 &#39;my @y[0]=3D{a=3D&gt;&quot;aa&quot;,b=3D&gt;&quot;bb&quot;}; push =
@y, {a=3D&gt;&quot;AA&quot;,b=3D&gt;&quot;BB&quot;}; for @y.kv <br>
-&gt; $I, $J { say &quot;Index $I=C2=A0 $J&lt;a&gt;=C2=A0 $J&lt;b&gt;&quot;=
 }; say &quot;elements &quot; ~ @y.elems;&#39;<br>
Illegal dimension in shape: 0. All dimensions must be integers bigger than =
0<br>
=C2=A0 =C2=A0in block &lt;unit&gt; at -e line 1<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">Fernando Santagata</div>

--0000000000009269fd0598cad772--
0
nando
12/3/2019 11:17:19 AM
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 <unit> at -e line 1


$ p6 'my @y; @y[0]={a=>"aa",b=>"bb"};'
<no complaining>
0
perl6
12/3/2019 11:35:13 AM
Reply: