I need hash inside a hash help

Hi All,

How do I do a hash inside a hash?

So far I have:

$ p6 'my %Vendors=("acme" => ( "ContactName" => "Larry, "AccountNo" => 
1234 ) ); say %Vendors;'
===SORRY!=== Error while compiling -e


I want to be able to have both a Contact Name and and AccountNo
associated with each key in %Vendors.


Many thanks,
-T
0
perl6
1/11/2019 6:41:48 PM
perl.perl6.users 1120 articles. 0 followers. Follow

19 Replies
16 Views

Similar Articles

[PageSpeed] 29

--000000000000c4d9d2057f336956
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

What would you say is the error, according to where the arrow points to?
Maybe some unclosed double quotes?

El vie., 11 ene. 2019 a las 19:57, ToddAndMargo via perl6-users (<
perl6-users@perl.org>) escribi=C3=B3:

> Hi All,
>
> How do I do a hash inside a hash?
>
> So far I have:
>
> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "AccountNo"=
 =3D>
> 1234 ) ); say %Vendors;'
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>
>
> I want to be able to have both a Contact Name and and AccountNo
> associated with each key in %Vendors.
>
>
> Many thanks,
> -T
>


--=20
JJ

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

<div dir=3D"ltr">What would you say is the error, according to where the ar=
row points to? Maybe some unclosed double quotes?<br></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr">El vie., 11 ene. 2019 a las 19:57, ToddAn=
dMargo via perl6-users (&lt;<a href=3D"mailto:perl6-users@perl.org">perl6-u=
sers@perl.org</a>&gt;) escribi=C3=B3:<br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,2=
04);padding-left:1ex">Hi All,<br>
<br>
How do I do a hash inside a hash?<br>
<br>
So far I have:<br>
<br>
$ p6 &#39;my %Vendors=3D(&quot;acme&quot; =3D&gt; ( &quot;ContactName&quot;=
 =3D&gt; &quot;Larry, &quot;AccountNo&quot; =3D&gt; <br>
1234 ) ); say %Vendors;&#39;<br>
=3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e<br>
<br>
<br>
I want to be able to have both a Contact Name and and AccountNo<br>
associated with each key in %Vendors.<br>
<br>
<br>
Many thanks,<br>
-T<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">JJ</div>

--000000000000c4d9d2057f336956--
0
jjmerelo
1/11/2019 7:07:37 PM
Hi Todd,

the error you're getting comes from a closing quotation mark missing
after "Larry

You will also need to give perl6 some hint that you want the list of
pairs to actually become a hash.

To do that, I would recommend just putting a % in front of the ()

The working code looks like this:

perl6 -e 'my %Vendors=3D("acme" =3D> %( "ContactName" =3D> "Larry",
"AccountNo" =3D> 1234 ) ); say %Vendors;'
{acme =3D> {AccountNo =3D> 1234, ContactName =3D> Larry}}

Hope that helps!
=C2=A0 - Timo

On 11/01/2019 19:41, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> How do I do a hash inside a hash?
>
> So far I have:
>
> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "AccountN=
o" =3D>
> 1234 ) ); say %Vendors;'
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>
>
> I want to be able to have both a Contact Name and and AccountNo
> associated with each key in %Vendors.
>
>
> Many thanks,
> -T
0
timo
1/11/2019 7:09:29 PM
On 1/11/19 11:09 AM, Timo Paulssen wrote:
> Hi Todd,
>=20
> the error you're getting comes from a closing quotation mark missing
> after "Larry
>=20
> You will also need to give perl6 some hint that you want the list of
> pairs to actually become a hash.
>=20
> To do that, I would recommend just putting a % in front of the ()
>=20
> The working code looks like this:
>=20
> perl6 -e 'my %Vendors=3D("acme" =3D> %( "ContactName" =3D> "Larry",
> "AccountNo" =3D> 1234 ) ); say %Vendors;'
> {acme =3D> {AccountNo =3D> 1234, ContactName =3D> Larry}}
>=20
> Hope that helps!
>  =C2=A0 - Timo
>=20
> On 11/01/2019 19:41, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> How do I do a hash inside a hash?
>>
>> So far I have:
>>
>> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "Account=
No" =3D>
>> 1234 ) ); say %Vendors;'
>> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>>
>>
>> I want to be able to have both a Contact Name and and AccountNo
>> associated with each key in %Vendors.
>>
>>
>> Many thanks,
>> -T


Hi Timo,

Thank you!

Ah man.  I took my best shot at it and got nailed by a stinkin' typo.

:'(

-T
0
perl6
1/11/2019 7:12:41 PM

> On Jan 11, 2019, at 12:41 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> Hi All,
>=20
> How do I do a hash inside a hash?
>=20
> So far I have:
>=20
> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, =
"AccountNo" =3D> 1234 ) ); say %Vendors;'
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>=20
>=20
> I want to be able to have both a Contact Name and and AccountNo
> associated with each key in %Vendors.
>=20
>=20
> Many thanks,
> -T

First, you need a double-quote after `Larry` (before the comma) to fix =
the syntax error:
	perl6 -e 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 ) ); say %Vendors;'

At this point, you have a Hash of List of Pairs. To change it into a =
Hash of Hashes, change the inner parens to curly braces:
	perl6 -e 'my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 } ); say %Vendors; say =
%Vendors<acme><AccountNo>;'

Those inner parens were acting as an anonymous list constructor, but you =
needed an anonymous *hash* constructor, which is what the curly braces =
do (when they are not doing their code-block-ish job).

You could have also used `Hash(=E2=80=A6)` or `%(=E2=80=A6)` instead of =
`{=E2=80=A6}`, but `{=E2=80=A6} is shortest, and most traditional from =
Perl 5.

=E2=80=94=20
Hope this helps,
Bruce Gray (Util of PerlMonks)
0
robertbrucegray3
1/11/2019 7:16:44 PM
On 1/11/19 11:07 AM, JJ Merelo wrote:
> What would you say is the error, according to where the arrow points to=
?=20
> Maybe some unclosed double quotes?
>=20
> El vie., 11 ene. 2019 a las 19:57, ToddAndMargo via perl6-users=20
> (<perl6-users@perl.org <mailto:perl6-users@perl.org>>) escribi=C3=B3:
>=20
>     Hi All,
>=20
>     How do I do a hash inside a hash?
>=20
>     So far I have:
>=20
>     $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "Acco=
untNo" =3D>
>     1234 ) ); say %Vendors;'
>     =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>=20
>=20
>     I want to be able to have both a Contact Name and and AccountNo
>     associated with each key in %Vendors.
>=20
>=20
>     Many thanks,
>     -T
>=20
>=20
>=20
> --=20
> JJ

I missed the quote after Larry.  Timo found it for me.
0
perl6
1/11/2019 7:16:58 PM
On 1/11/19 11:12 AM, ToddAndMargo via perl6-users wrote:
> On 1/11/19 11:09 AM, Timo Paulssen wrote:
>> Hi Todd,
>>
>> the error you're getting comes from a closing quotation mark missing
>> after "Larry
>>
>> You will also need to give perl6 some hint that you want the list of
>> pairs to actually become a hash.
>>
>> To do that, I would recommend just putting a % in front of the ()
>>
>> The working code looks like this:
>>
>> perl6 -e 'my %Vendors=3D("acme" =3D> %( "ContactName" =3D> "Larry",
>> "AccountNo" =3D> 1234 ) ); say %Vendors;'
>> {acme =3D> {AccountNo =3D> 1234, ContactName =3D> Larry}}
>>
>> Hope that helps!
>> =C2=A0=C2=A0 - Timo
>>
>> On 11/01/2019 19:41, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> How do I do a hash inside a hash?
>>>
>>> So far I have:
>>>
>>> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "Accoun=
tNo" =3D>
>>> 1234 ) ); say %Vendors;'
>>> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>>>
>>>
>>> I want to be able to have both a Contact Name and and AccountNo
>>> associated with each key in %Vendors.
>>>
>>>
>>> Many thanks,
>>> -T
>=20
>=20
> Hi Timo,
>=20
> Thank you!
>=20
> Ah man.=C2=A0 I took my best shot at it and got nailed by a stinkin' ty=
po.
>=20
> :'(
>=20
> -T


Not to ask too stupid a question, but how do I get the values back out?

p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry", "AccountNo" =
=3D>=20
1234 ), "Ace" =3D> ( "ContactName" =3D> "Mo", "AccountNo" =3D> "A102" ); =
say=20
%Vendors<"Ace"<"ContactName">>;'
0
perl6
1/11/2019 7:17:41 PM
On 1/11/19 11:16 AM, Bruce Gray wrote:
>=20
>=20
>> On Jan 11, 2019, at 12:41 PM, ToddAndMargo via perl6-users <perl6-user=
s@perl.org> wrote:
>>
>> Hi All,
>>
>> How do I do a hash inside a hash?
>>
>> So far I have:
>>
>> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "Account=
No" =3D> 1234 ) ); say %Vendors;'
>> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>>
>>
>> I want to be able to have both a Contact Name and and AccountNo
>> associated with each key in %Vendors.
>>
>>
>> Many thanks,
>> -T
>=20
> First, you need a double-quote after `Larry` (before the comma) to fix =
the syntax error:
> 	perl6 -e 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry", "Ac=
countNo" =3D> 1234 ) ); say %Vendors;'
>=20
> At this point, you have a Hash of List of Pairs. To change it into a Ha=
sh of Hashes, change the inner parens to curly braces:
> 	perl6 -e 'my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Larry", "Ac=
countNo" =3D> 1234 } ); say %Vendors; say %Vendors<acme><AccountNo>;'
>=20
> Those inner parens were acting as an anonymous list constructor, but yo=
u needed an anonymous *hash* constructor, which is what the curly braces =
do (when they are not doing their code-block-ish job).
>=20
> You could have also used `Hash(=E2=80=A6)` or `%(=E2=80=A6)` instead of=
 `{=E2=80=A6}`, but `{=E2=80=A6} is shortest, and most traditional from P=
erl 5.
>=20
> =E2=80=94
> Hope this helps,
> Bruce Gray (Util of PerlMonks)
>=20

Hi Bruce,

Thank you!

This works,

$ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",=20
"AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>=20
"A102" } ); say "%Vendors<Ace><ContactName>" ~ "\t" ~=20
"%Vendors<Ace><AccountNo>";'
Mo	A102


but I have to access it by a variable.  "Now" what am I doing wrong?

$ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",=20
"AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>=20
"A102" } ); say "%Vendors<$Ace><ContactName>" ~ "\t" ~=20
"%Vendors<$Ace><AccountNo>";'
Use of uninitialized value of type Any in string context.


Many thanks,
-T
0
perl6
1/11/2019 7:25:31 PM
--000000000000a7571f057f33c4ca
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I think you want $x, not $Ace.

Cheers

El vie., 11 ene. 2019 a las 20:26, ToddAndMargo via perl6-users (<
perl6-users@perl.org>) escribi=C3=B3:

> On 1/11/19 11:16 AM, Bruce Gray wrote:
> >
> >
> >> On Jan 11, 2019, at 12:41 PM, ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
> >>
> >> Hi All,
> >>
> >> How do I do a hash inside a hash?
> >>
> >> So far I have:
> >>
> >> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, "Account=
No" =3D>
> 1234 ) ); say %Vendors;'
> >> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
> >>
> >>
> >> I want to be able to have both a Contact Name and and AccountNo
> >> associated with each key in %Vendors.
> >>
> >>
> >> Many thanks,
> >> -T
> >
> > First, you need a double-quote after `Larry` (before the comma) to fix
> the syntax error:
> >       perl6 -e 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry"=
,
> "AccountNo" =3D> 1234 ) ); say %Vendors;'
> >
> > At this point, you have a Hash of List of Pairs. To change it into a
> Hash of Hashes, change the inner parens to curly braces:
> >       perl6 -e 'my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Larry"=
,
> "AccountNo" =3D> 1234 } ); say %Vendors; say %Vendors<acme><AccountNo>;'
> >
> > Those inner parens were acting as an anonymous list constructor, but yo=
u
> needed an anonymous *hash* constructor, which is what the curly braces do
> (when they are not doing their code-block-ish job).
> >
> > You could have also used `Hash(=E2=80=A6)` or `%(=E2=80=A6)` instead of=
 `{=E2=80=A6}`, but `{=E2=80=A6}
> is shortest, and most traditional from Perl 5.
> >
> > =E2=80=94
> > Hope this helps,
> > Bruce Gray (Util of PerlMonks)
> >
>
> Hi Bruce,
>
> Thank you!
>
> This works,
>
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>
> "A102" } ); say "%Vendors<Ace><ContactName>" ~ "\t" ~
> "%Vendors<Ace><AccountNo>";'
> Mo      A102
>
>
> but I have to access it by a variable.  "Now" what am I doing wrong?
>
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>
> "A102" } ); say "%Vendors<$Ace><ContactName>" ~ "\t" ~
> "%Vendors<$Ace><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>
>
> Many thanks,
> -T
>


--=20
JJ

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

<div dir=3D"ltr"><div>I think you want $x, not $Ace.</div><div><br></div><d=
iv>Cheers<br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">El=
 vie., 11 ene. 2019 a las 20:26, ToddAndMargo via perl6-users (&lt;<a href=
=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt;) escribi=C3=
=B3:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 1/11/19 =
11:16 AM, Bruce Gray wrote:<br>
&gt; <br>
&gt; <br>
&gt;&gt; On Jan 11, 2019, at 12:41 PM, ToddAndMargo via perl6-users &lt;<a =
href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-users@perl.org=
</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi All,<br>
&gt;&gt;<br>
&gt;&gt; How do I do a hash inside a hash?<br>
&gt;&gt;<br>
&gt;&gt; So far I have:<br>
&gt;&gt;<br>
&gt;&gt; $ p6 &#39;my %Vendors=3D(&quot;acme&quot; =3D&gt; ( &quot;ContactN=
ame&quot; =3D&gt; &quot;Larry, &quot;AccountNo&quot; =3D&gt; 1234 ) ); say =
%Vendors;&#39;<br>
&gt;&gt; =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; I want to be able to have both a Contact Name and and AccountNo<br=
>
&gt;&gt; associated with each key in %Vendors.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Many thanks,<br>
&gt;&gt; -T<br>
&gt; <br>
&gt; First, you need a double-quote after `Larry` (before the comma) to fix=
 the syntax error:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0perl6 -e &#39;my %Vendors=3D(&quot;acme&quot=
; =3D&gt; ( &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, &quot;Accoun=
tNo&quot; =3D&gt; 1234 ) ); say %Vendors;&#39;<br>
&gt; <br>
&gt; At this point, you have a Hash of List of Pairs. To change it into a H=
ash of Hashes, change the inner parens to curly braces:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0perl6 -e &#39;my %Vendors=3D(&quot;acme&quot=
; =3D&gt; { &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, &quot;Accoun=
tNo&quot; =3D&gt; 1234 } ); say %Vendors; say %Vendors&lt;acme&gt;&lt;Accou=
ntNo&gt;;&#39;<br>
&gt; <br>
&gt; Those inner parens were acting as an anonymous list constructor, but y=
ou needed an anonymous *hash* constructor, which is what the curly braces d=
o (when they are not doing their code-block-ish job).<br>
&gt; <br>
&gt; You could have also used `Hash(=E2=80=A6)` or `%(=E2=80=A6)` instead o=
f `{=E2=80=A6}`, but `{=E2=80=A6} is shortest, and most traditional from Pe=
rl 5.<br>
&gt; <br>
&gt; =E2=80=94<br>
&gt; Hope this helps,<br>
&gt; Bruce Gray (Util of PerlMonks)<br>
&gt; <br>
<br>
Hi Bruce,<br>
<br>
Thank you!<br>
<br>
This works,<br>
<br>
$ p6 &#39;my $x=3D&quot;Ace&quot;; my %Vendors=3D(&quot;acme&quot; =3D&gt; =
{ &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, <br>
&quot;AccountNo&quot; =3D&gt; 1234 }, &quot;Ace&quot; =3D&gt; { &quot;Conta=
ctName&quot; =3D&gt; &quot;Mo&quot;, &quot;AccountNo&quot; =3D&gt; <br>
&quot;A102&quot; } ); say &quot;%Vendors&lt;Ace&gt;&lt;ContactName&gt;&quot=
; ~ &quot;\t&quot; ~ <br>
&quot;%Vendors&lt;Ace&gt;&lt;AccountNo&gt;&quot;;&#39;<br>
Mo=C2=A0 =C2=A0 =C2=A0 A102<br>
<br>
<br>
but I have to access it by a variable.=C2=A0 &quot;Now&quot; what am I doin=
g wrong?<br>
<br>
$ p6 &#39;my $x=3D&quot;Ace&quot;; my %Vendors=3D(&quot;acme&quot; =3D&gt; =
{ &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, <br>
&quot;AccountNo&quot; =3D&gt; 1234 }, &quot;Ace&quot; =3D&gt; { &quot;Conta=
ctName&quot; =3D&gt; &quot;Mo&quot;, &quot;AccountNo&quot; =3D&gt; <br>
&quot;A102&quot; } ); say &quot;%Vendors&lt;$Ace&gt;&lt;ContactName&gt;&quo=
t; ~ &quot;\t&quot; ~ <br>
&quot;%Vendors&lt;$Ace&gt;&lt;AccountNo&gt;&quot;;&#39;<br>
Use of uninitialized value of type Any in string context.<br>
<br>
<br>
Many thanks,<br>
-T<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">JJ</div>

--000000000000a7571f057f33c4ca--
0
jjmerelo
1/11/2019 7:33:05 PM
On 1/11/19 11:33 AM, JJ Merelo wrote:
> I think you want $x, not $Ace.
> 
> Cheers

Yup.  I am on fire today!  :'(

Still can't get it figured out.  :'(  :'(

$ p6 'my $x="Ace"; my %Vendors=("acme" => { "ContactName" => "Larry", 
"AccountNo" => 1234 }, "Ace" => { "ContactName" => "Mo", "AccountNo" => 
"A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~ 
"%Vendors<$x><AccountNo>";'
Use of uninitialized value of type Any in string context.

	
$ p6 'my $x="Ace"; my %Vendors=("acme" => { "ContactName" => "Larry", 
"AccountNo" => 1234 }, "Ace" => { "ContactName" => "Mo", "AccountNo" => 
"A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~ 
"%Vendors<"$x"><AccountNo>";'
Use of uninitialized value of type Any in string context.
	
$ p6 'my $x="Ace"; my %Vendors=("acme" => { "ContactName" => "Larry", 
"AccountNo" => 1234 }, "Ace" => { "ContactName" => "Mo", "AccountNo" => 
"A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~ 
"%Vendors<{$x}><AccountNo>";'
Use of uninitialized value of type Any in string context.

$ p6 'my $x="Ace"; my %Vendors=("acme" => { "ContactName" => "Larry", 
"AccountNo" => 1234 }, "Ace" => { "ContactName" => "Mo", "AccountNo" => 
"A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" ~ 
"%Vendors<{"$x"}><AccountNo>";'
Use of uninitialized value of type Any in string context.


I can't win.
0
perl6
1/11/2019 7:39:15 PM
On 1/11/19 11:39 AM, ToddAndMargo via perl6-users wrote:
> On 1/11/19 11:33 AM, JJ Merelo wrote:
>> I think you want $x, not $Ace.
>>
>> Cheers
>=20
> Yup.=C2=A0 I am on fire today!=C2=A0 :'(
>=20
> Still can't get it figured out.=C2=A0 :'(=C2=A0 :'(
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "L=
arry",=20
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Account=
No" =3D>=20
> "A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~=20
> "%Vendors<$x><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "L=
arry",=20
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Account=
No" =3D>=20
> "A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~=20
> "%Vendors<"$x"><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "L=
arry",=20
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Account=
No" =3D>=20
> "A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~=20
> "%Vendors<{$x}><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "L=
arry",=20
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Account=
No" =3D>=20
> "A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" ~=20
> "%Vendors<{"$x"}><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
>=20
> I can't win.


$ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",=20
"AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>=20
"A102" } ); say "%Vendors<<$x>><ContactName>" ~ "\t" ~=20
"%Vendors<<$x>><AccountNo>";'
=3D=3D=3DSORRY!=3D=3D=3D
Unable to parse expression in double quotes; couldn't find final '"'=20
(corresponding starter was at line 1)
at -e:1
------> >" ~ "\t" ~ "%Vendors<<$x>><AccountNo>";=E2=8F=8F<EOL>
     expecting any of:
         double quotes
         postfix
Other potential difficulties:
     Ambiguous use of >>; use =C2=BB instead to mean hyper, or insert=20
whitespace before >> to mean a quote terminator (or use different=20
delimiters?)
     at -e:1
     ------> 2" } ); say "%Vendors<<$x>><ContactName>=E2=8F=8F" ~ "\t" ~ =

"%Vendors<<$x>><AccountNo>";
     Ambiguous use of >>; use =C2=BB instead to mean hyper, or insert=20
whitespace before >> to mean a quote terminator (or use different=20
delimiters?)
     at -e:1
     ------> me>" ~ "\t" ~ "%Vendors<<$x>><AccountNo>=E2=8F=8F";
0
perl6
1/11/2019 7:43:30 PM
Short answer: use `%hash{$var}`, not `%hash<$var>`.

When they are not in position to be less-than and greater-than =
comparison operators, the pair of left and right angle brackets are a =
circumfix operator that work like Perl 5=E2=80=99s =E2=80=9Cquote =
word=E2=80=9D op: `qw()`.

In Perl 6, `<>` are used a lot, including as a shortcut in hash lookups.
The full form for looking up the constant key `acme` in %Vendors is to =
use curly braces and to *quote* the key (single or double quote), or =
have the key in a variable:
	say %Vendors{'acme=E2=80=99};
	say %Vendors{"acme=E2=80=9D};
	my $k =3D =E2=80=98acme=E2=80=99;
	say %Vendors{$k};
The shortcut of replacing the curly braces with angle brackets only =
works for constant strings:
	say %Vendors<acme>;

Advanced note: Since `<>` produce a *list* of quoted words, you can use =
them to extract multiple values from a hash:
	my ( $acct, $cn ) =3D %Vendors{"acme"}{"AccountNo", =
"ContactName=E2=80=9D};
	my ( $acct, $cn ) =3D %Vendors<acme><AccountNo ContactName>;
	say [:$acct, :$cn].perl;

--=20
Hope this helps,
Bruce Gray (Util of PerlMonks)



> On Jan 11, 2019, at 1:25 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> On 1/11/19 11:16 AM, Bruce Gray wrote:
>>> On Jan 11, 2019, at 12:41 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>>>=20
>>> Hi All,
>>>=20
>>> How do I do a hash inside a hash?
>>>=20
>>> So far I have:
>>>=20
>>> $ p6 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> "Larry, =
"AccountNo" =3D> 1234 ) ); say %Vendors;'
>>> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling -e
>>>=20
>>>=20
>>> I want to be able to have both a Contact Name and and AccountNo
>>> associated with each key in %Vendors.
>>>=20
>>>=20
>>> Many thanks,
>>> -T
>> First, you need a double-quote after `Larry` (before the comma) to =
fix the syntax error:
>> 	perl6 -e 'my %Vendors=3D("acme" =3D> ( "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 ) ); say %Vendors;'
>> At this point, you have a Hash of List of Pairs. To change it into a =
Hash of Hashes, change the inner parens to curly braces:
>> 	perl6 -e 'my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 } ); say %Vendors; say =
%Vendors<acme><AccountNo>;'
>> Those inner parens were acting as an anonymous list constructor, but =
you needed an anonymous *hash* constructor, which is what the curly =
braces do (when they are not doing their code-block-ish job).
>> You could have also used `Hash(=E2=80=A6)` or `%(=E2=80=A6)` instead =
of `{=E2=80=A6}`, but `{=E2=80=A6} is shortest, and most traditional =
from Perl 5.
>> =E2=80=94
>> Hope this helps,
>> Bruce Gray (Util of PerlMonks)
>=20
> Hi Bruce,
>=20
> Thank you!
>=20
> This works,
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<Ace><ContactName>" ~ "\t" ~ =
"%Vendors<Ace><AccountNo>";'
> Mo	A102
>=20
>=20
> but I have to access it by a variable.  "Now" what am I doing wrong?
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<$Ace><ContactName>" ~ "\t" ~ =
"%Vendors<$Ace><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
>=20
> Many thanks,
> -T
0
robertbrucegray3
1/11/2019 7:45:00 PM
--000000000000bd5599057f33efe2
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

You don't need to quote "%Vendors<{"$x"}><ContactName>"By doing so, you're
closing the quotes right behind {

Cheers

El vie., 11 ene. 2019 a las 20:39, ToddAndMargo via perl6-users (<
perl6-users@perl.org>) escribi=C3=B3:

> On 1/11/19 11:33 AM, JJ Merelo wrote:
> > I think you want $x, not $Ace.
> >
> > Cheers
>
> Yup.  I am on fire today!  :'(
>
> Still can't get it figured out.  :'(  :'(
>
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>
> "A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~
> "%Vendors<$x><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>
>
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>
> "A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~
> "%Vendors<"$x"><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>
> "A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~
> "%Vendors<{$x}><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "Lar=
ry",
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "AccountNo=
" =3D>
> "A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" ~
> "%Vendors<{"$x"}><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>
>
> I can't win.
>


--=20
JJ

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

<div dir=3D"ltr"><div>You don&#39;t need to quote &quot;%Vendors&lt;{&quot;=
$x&quot;}&gt;&lt;ContactName&gt;&quot;By doing so, you&#39;re closing the q=
uotes right behind {</div><div><br></div><div>Cheers<br></div></div><br><di=
v class=3D"gmail_quote"><div dir=3D"ltr">El vie., 11 ene. 2019 a las 20:39,=
 ToddAndMargo via perl6-users (&lt;<a href=3D"mailto:perl6-users@perl.org">=
perl6-users@perl.org</a>&gt;) escribi=C3=B3:<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(20=
4,204,204);padding-left:1ex">On 1/11/19 11:33 AM, JJ Merelo wrote:<br>
&gt; I think you want $x, not $Ace.<br>
&gt; <br>
&gt; Cheers<br>
<br>
Yup.=C2=A0 I am on fire today!=C2=A0 :&#39;(<br>
<br>
Still can&#39;t get it figured out.=C2=A0 :&#39;(=C2=A0 :&#39;(<br>
<br>
$ p6 &#39;my $x=3D&quot;Ace&quot;; my %Vendors=3D(&quot;acme&quot; =3D&gt; =
{ &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, <br>
&quot;AccountNo&quot; =3D&gt; 1234 }, &quot;Ace&quot; =3D&gt; { &quot;Conta=
ctName&quot; =3D&gt; &quot;Mo&quot;, &quot;AccountNo&quot; =3D&gt; <br>
&quot;A102&quot; } ); say &quot;%Vendors&lt;$x&gt;&lt;ContactName&gt;&quot;=
 ~ &quot;\t&quot; ~ <br>
&quot;%Vendors&lt;$x&gt;&lt;AccountNo&gt;&quot;;&#39;<br>
Use of uninitialized value of type Any in string context.<br>
<br>
<br>
$ p6 &#39;my $x=3D&quot;Ace&quot;; my %Vendors=3D(&quot;acme&quot; =3D&gt; =
{ &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, <br>
&quot;AccountNo&quot; =3D&gt; 1234 }, &quot;Ace&quot; =3D&gt; { &quot;Conta=
ctName&quot; =3D&gt; &quot;Mo&quot;, &quot;AccountNo&quot; =3D&gt; <br>
&quot;A102&quot; } ); say &quot;%Vendors&lt;&quot;$x&quot;&gt;&lt;ContactNa=
me&gt;&quot; ~ &quot;\t&quot; ~ <br>
&quot;%Vendors&lt;&quot;$x&quot;&gt;&lt;AccountNo&gt;&quot;;&#39;<br>
Use of uninitialized value of type Any in string context.<br>
<br>
$ p6 &#39;my $x=3D&quot;Ace&quot;; my %Vendors=3D(&quot;acme&quot; =3D&gt; =
{ &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, <br>
&quot;AccountNo&quot; =3D&gt; 1234 }, &quot;Ace&quot; =3D&gt; { &quot;Conta=
ctName&quot; =3D&gt; &quot;Mo&quot;, &quot;AccountNo&quot; =3D&gt; <br>
&quot;A102&quot; } ); say &quot;%Vendors&lt;{$x}&gt;&lt;ContactName&gt;&quo=
t; ~ &quot;\t&quot; ~ <br>
&quot;%Vendors&lt;{$x}&gt;&lt;AccountNo&gt;&quot;;&#39;<br>
Use of uninitialized value of type Any in string context.<br>
<br>
$ p6 &#39;my $x=3D&quot;Ace&quot;; my %Vendors=3D(&quot;acme&quot; =3D&gt; =
{ &quot;ContactName&quot; =3D&gt; &quot;Larry&quot;, <br>
&quot;AccountNo&quot; =3D&gt; 1234 }, &quot;Ace&quot; =3D&gt; { &quot;Conta=
ctName&quot; =3D&gt; &quot;Mo&quot;, &quot;AccountNo&quot; =3D&gt; <br>
&quot;A102&quot; } ); say &quot;%Vendors&lt;{&quot;$x&quot;}&gt;&lt;Contact=
Name&gt;&quot; ~ &quot;\t&quot; ~ <br>
&quot;%Vendors&lt;{&quot;$x&quot;}&gt;&lt;AccountNo&gt;&quot;;&#39;<br>
Use of uninitialized value of type Any in string context.<br>
<br>
<br>
I can&#39;t win.<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">JJ</div>

--000000000000bd5599057f33efe2--
0
jjmerelo
1/11/2019 7:45:08 PM

> On Jan 11, 2019, at 1:39 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> On 1/11/19 11:33 AM, JJ Merelo wrote:
>> I think you want $x, not $Ace.
>> Cheers
>=20
> Yup.  I am on fire today!  :'(
>=20
> Still can't get it figured out.  :'(  :'(
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~ =
"%Vendors<$x><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
> =09
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~ =
"%Vendors<"$x"><AccountNo>";'
> Use of uninitialized value of type Any in string context.
> =09
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~ =
"%Vendors<{$x}><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" =
~ "%Vendors<{"$x"}><AccountNo>";'
> Use of uninitialized value of type Any in string context.
>=20
>=20
> I can't win.


This:
	<{"$x=E2=80=9D}>
should just be:
	{$x}


(Lots of unneeded double-quotes trimmed)
perl6 -e 'my $x =3D "Ace"; my %Vendors =3D ( acme =3D> { ContactName =3D> =
"Larry", AccountNo =3D> 1234 }, Ace =3D> { ContactName =3D> "Mo", =
AccountNo =3D> "A102" } ); say %Vendors{$x}<ContactName> ~ "\t" ~ =
%Vendors{$x}<AccountNo>;=E2=80=99
0
robertbrucegray3
1/11/2019 7:50:01 PM
On 1/11/19 11:43 AM, ToddAndMargo via perl6-users wrote:
> On 1/11/19 11:39 AM, ToddAndMargo via perl6-users wrote:
>> On 1/11/19 11:33 AM, JJ Merelo wrote:
>>> I think you want $x, not $Ace.
>>>
>>> Cheers
>>
>> Yup.=C2=A0 I am on fire today!=C2=A0 :'(
>>
>> Still can't get it figured out.=C2=A0 :'(=C2=A0 :'(
>>
>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "=
Larry",=20
>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accoun=
tNo"=20
>> =3D> "A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~=20
>> "%Vendors<$x><AccountNo>";'
>> Use of uninitialized value of type Any in string context.
>>
>>
>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "=
Larry",=20
>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accoun=
tNo"=20
>> =3D> "A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~=20
>> "%Vendors<"$x"><AccountNo>";'
>> Use of uninitialized value of type Any in string context.
>>
>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "=
Larry",=20
>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accoun=
tNo"=20
>> =3D> "A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~=20
>> "%Vendors<{$x}><AccountNo>";'
>> Use of uninitialized value of type Any in string context.
>>
>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "=
Larry",=20
>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accoun=
tNo"=20
>> =3D> "A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" ~=20
>> "%Vendors<{"$x"}><AccountNo>";'
>> Use of uninitialized value of type Any in string context.
>>
>>
>> I can't win.
>=20
>=20
> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "L=
arry",=20
> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Account=
No" =3D>=20
> "A102" } ); say "%Vendors<<$x>><ContactName>" ~ "\t" ~=20
> "%Vendors<<$x>><AccountNo>";'
> =3D=3D=3DSORRY!=3D=3D=3D
> Unable to parse expression in double quotes; couldn't find final '"'=20
> (corresponding starter was at line 1)
> at -e:1
> ------> >" ~ "\t" ~ "%Vendors<<$x>><AccountNo>";=E2=8F=8F<EOL>
>  =C2=A0=C2=A0=C2=A0 expecting any of:
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 double quotes
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 postfix
> Other potential difficulties:
>  =C2=A0=C2=A0=C2=A0 Ambiguous use of >>; use =C2=BB instead to mean hyp=
er, or insert=20
> whitespace before >> to mean a quote terminator (or use different=20
> delimiters?)
>  =C2=A0=C2=A0=C2=A0 at -e:1
>  =C2=A0=C2=A0=C2=A0 ------> 2" } ); say "%Vendors<<$x>><ContactName>=E2=
=8F=8F" ~ "\t" ~=20
> "%Vendors<<$x>><AccountNo>";
>  =C2=A0=C2=A0=C2=A0 Ambiguous use of >>; use =C2=BB instead to mean hyp=
er, or insert=20
> whitespace before >> to mean a quote terminator (or use different=20
> delimiters?)
>  =C2=A0=C2=A0=C2=A0 at -e:1
>  =C2=A0=C2=A0=C2=A0 ------> me>" ~ "\t" ~ "%Vendors<<$x>><AccountNo>=E2=
=8F=8F";


I got it finally.  I had to switch from a one liner to an actual program


<code HashOfHashTest.pl6>
#! /usr/bin/env perl6

my $x       =3D "Ace";
my %Vendors =3D ( "acme" =3D> { "ContactName" =3D> "Larry", "AccountNo" =3D=
>=20
1234 },
                 "Ace" =3D>  { "ContactName" =3D> "Mo",    "AccountNo" =3D=
>=20
"A102" } );

print( %Vendors<< $x >><ContactName> ~ "\t" ~ %Vendors<< $x=20
 >><AccountNo> ~ "\n" );
<M/code>


$ HashOfHashTest.pl6
Mo	A102

And it demanded a white space in << $x >>
0
perl6
1/11/2019 7:50:30 PM
On 1/11/19 11:50 AM, Bruce Gray wrote:
> 'my $x =3D "Ace"; my %Vendors =3D ( acme =3D> { ContactName =3D> "Larry=
", AccountNo =3D> 1234 }, Ace =3D> { ContactName =3D> "Mo", AccountNo =3D=
> "A102" } ); say %Vendors{$x}<ContactName> ~ "\t" ~ %Vendors{$x}<Account=
No>;=E2=80=99

Hi Bruce,

Sweet!  Thank you!

$ p6 'my $x =3D "Ace"; my %Vendors =3D ( acme =3D> { ContactName =3D> "La=
rry",=20
AccountNo =3D> 1234 }, Ace =3D> { ContactName =3D> "Mo", AccountNo =3D> "=
A102" }=20
); say %Vendors{$x}<ContactName> ~ "\t" ~ %Vendors{$x}<AccountNo>;'

Mo	A102

-T
0
perl6
1/11/2019 7:55:15 PM
On 1/11/19 11:45 AM, Bruce Gray wrote:
> Short answer: use `%hash{$var}`, not `%hash<$var>`.
>=20
> When they are not in position to be less-than and greater-than comparis=
on operators, the pair of left and right angle brackets are a circumfix o=
perator that work like Perl 5=E2=80=99s =E2=80=9Cquote word=E2=80=9D op: =
`qw()`.
>=20
> In Perl 6, `<>` are used a lot, including as a shortcut in hash lookups=
=2E
> The full form for looking up the constant key `acme` in %Vendors is to =
use curly braces and to*quote*  the key (single or double quote), or have=
 the key in a variable:
> 	say %Vendors{'acme=E2=80=99};
> 	say %Vendors{"acme=E2=80=9D};
> 	my $k =3D =E2=80=98acme=E2=80=99;
> 	say %Vendors{$k};
> The shortcut of replacing the curly braces with angle brackets only wor=
ks for constant strings:
> 	say %Vendors<acme>;
>=20
> Advanced note: Since `<>` produce a*list*  of quoted words, you can use=
 them to extract multiple values from a hash:
> 	my ( $acct, $cn ) =3D %Vendors{"acme"}{"AccountNo", "ContactName=E2=80=
=9D};
> 	my ( $acct, $cn ) =3D %Vendors<acme><AccountNo ContactName>;
> 	say [:$acct, :$cn].perl;


Yes it does help.  I copied it to my hash Keepers file.  Thank you!
0
perl6
1/11/2019 7:58:41 PM
That may work, but is bad practice.
Instead of:
	%Vendors<< $x >><ContactName>
, please use:
	%Vendors{$x}<ContactName>

The relation of `<<=E2=80=A6>>` is to `<=E2=80=A6>` as double-quotes are =
to single-quotes; doubling up changes from non-interpolating to =
interpolating.

To say `%Vendors<< $x >>` is to take the shortcut intended for constant =
keys, and bludgeon it to make it support variable keys, when the basic =
(and shorter) syntax of `%Vendors{$x}` handles the variable key =
naturally.

=E2=80=94=20
Hope this helps,
Bruce Gray (Util of PerlMonks)


> On Jan 11, 2019, at 1:50 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> On 1/11/19 11:43 AM, ToddAndMargo via perl6-users wrote:
>> On 1/11/19 11:39 AM, ToddAndMargo via perl6-users wrote:
>>> On 1/11/19 11:33 AM, JJ Merelo wrote:
>>>> I think you want $x, not $Ace.
>>>>=20
>>>> Cheers
>>>=20
>>> Yup.  I am on fire today!  :'(
>>>=20
>>> Still can't get it figured out.  :'(  :'(
>>>=20
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~ =
"%Vendors<$x><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>=20
>>>=20
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~ =
"%Vendors<"$x"><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>=20
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~ =
"%Vendors<{$x}><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>=20
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" =
~ "%Vendors<{"$x"}><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>=20
>>>=20
>>> I can't win.
>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry", "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", =
"AccountNo" =3D> "A102" } ); say "%Vendors<<$x>><ContactName>" ~ "\t" ~ =
"%Vendors<<$x>><AccountNo>";'
>> =3D=3D=3DSORRY!=3D=3D=3D
>> Unable to parse expression in double quotes; couldn't find final '"' =
(corresponding starter was at line 1)
>> at -e:1
>> ------> >" ~ "\t" ~ "%Vendors<<$x>><AccountNo>";=E2=8F=8F<EOL>
>>     expecting any of:
>>         double quotes
>>         postfix
>> Other potential difficulties:
>>     Ambiguous use of >>; use =C2=BB instead to mean hyper, or insert =
whitespace before >> to mean a quote terminator (or use different =
delimiters?)
>>     at -e:1
>>     ------> 2" } ); say "%Vendors<<$x>><ContactName>=E2=8F=8F" ~ "\t" =
~ "%Vendors<<$x>><AccountNo>";
>>     Ambiguous use of >>; use =C2=BB instead to mean hyper, or insert =
whitespace before >> to mean a quote terminator (or use different =
delimiters?)
>>     at -e:1
>>     ------> me>" ~ "\t" ~ "%Vendors<<$x>><AccountNo>=E2=8F=8F";
>=20
>=20
> I got it finally.  I had to switch from a one liner to an actual =
program
>=20
>=20
> <code HashOfHashTest.pl6>
> #! /usr/bin/env perl6
>=20
> my $x       =3D "Ace";
> my %Vendors =3D ( "acme" =3D> { "ContactName" =3D> "Larry", =
"AccountNo" =3D> 1234 },
>                "Ace" =3D>  { "ContactName" =3D> "Mo",    "AccountNo" =
=3D> "A102" } );
>=20
> print( %Vendors<< $x >><ContactName> ~ "\t" ~ %Vendors<< $x =
>><AccountNo> ~ "\n" );
> <M/code>
>=20
>=20
> $ HashOfHashTest.pl6
> Mo	A102
>=20
> And it demanded a white space in << $x >>
0
robertbrucegray3
1/11/2019 7:59:20 PM
On 1/11/19 11:50 AM, ToddAndMargo via perl6-users wrote:
> On 1/11/19 11:43 AM, ToddAndMargo via perl6-users wrote:
>> On 1/11/19 11:39 AM, ToddAndMargo via perl6-users wrote:
>>> On 1/11/19 11:33 AM, JJ Merelo wrote:
>>>> I think you want $x, not $Ace.
>>>>
>>>> Cheers
>>>
>>> Yup.=C2=A0 I am on fire today!=C2=A0 :'(
>>>
>>> Still can't get it figured out.=C2=A0 :'(=C2=A0 :'(
>>>
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry",=20
>>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accou=
ntNo"=20
>>> =3D> "A102" } ); say "%Vendors<$x><ContactName>" ~ "\t" ~=20
>>> "%Vendors<$x><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>
>>>
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry",=20
>>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accou=
ntNo"=20
>>> =3D> "A102" } ); say "%Vendors<"$x"><ContactName>" ~ "\t" ~=20
>>> "%Vendors<"$x"><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry",=20
>>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accou=
ntNo"=20
>>> =3D> "A102" } ); say "%Vendors<{$x}><ContactName>" ~ "\t" ~=20
>>> "%Vendors<{$x}><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>
>>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> =
"Larry",=20
>>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accou=
ntNo"=20
>>> =3D> "A102" } ); say "%Vendors<{"$x"}><ContactName>" ~ "\t" ~=20
>>> "%Vendors<{"$x"}><AccountNo>";'
>>> Use of uninitialized value of type Any in string context.
>>>
>>>
>>> I can't win.
>>
>>
>> $ p6 'my $x=3D"Ace"; my %Vendors=3D("acme" =3D> { "ContactName" =3D> "=
Larry",=20
>> "AccountNo" =3D> 1234 }, "Ace" =3D> { "ContactName" =3D> "Mo", "Accoun=
tNo"=20
>> =3D> "A102" } ); say "%Vendors<<$x>><ContactName>" ~ "\t" ~=20
>> "%Vendors<<$x>><AccountNo>";'
>> =3D=3D=3DSORRY!=3D=3D=3D
>> Unable to parse expression in double quotes; couldn't find final '"'=20
>> (corresponding starter was at line 1)
>> at -e:1
>> ------> >" ~ "\t" ~ "%Vendors<<$x>><AccountNo>";=E2=8F=8F<EOL>
>> =C2=A0=C2=A0=C2=A0=C2=A0 expecting any of:
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 double quotes
>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 postfix
>> Other potential difficulties:
>> =C2=A0=C2=A0=C2=A0=C2=A0 Ambiguous use of >>; use =C2=BB instead to me=
an hyper, or insert=20
>> whitespace before >> to mean a quote terminator (or use different=20
>> delimiters?)
>> =C2=A0=C2=A0=C2=A0=C2=A0 at -e:1
>> =C2=A0=C2=A0=C2=A0=C2=A0 ------> 2" } ); say "%Vendors<<$x>><ContactNa=
me>=E2=8F=8F" ~ "\t" ~=20
>> "%Vendors<<$x>><AccountNo>";
>> =C2=A0=C2=A0=C2=A0=C2=A0 Ambiguous use of >>; use =C2=BB instead to me=
an hyper, or insert=20
>> whitespace before >> to mean a quote terminator (or use different=20
>> delimiters?)
>> =C2=A0=C2=A0=C2=A0=C2=A0 at -e:1
>> =C2=A0=C2=A0=C2=A0=C2=A0 ------> me>" ~ "\t" ~ "%Vendors<<$x>><Account=
No>=E2=8F=8F";
>=20
>=20
> I got it finally.=C2=A0 I had to switch from a one liner to an actual p=
rogram
>=20
>=20
> <code HashOfHashTest.pl6>
> #! /usr/bin/env perl6
>=20
> my $x=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D "Ace";
> my %Vendors =3D ( "acme" =3D> { "ContactName" =3D> "Larry", "AccountNo"=
 =3D>=20
> 1234 },
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 "Ace" =3D>=C2=A0 { "ContactName" =3D> "Mo",=C2=A0=C2=A0=
=C2=A0 "AccountNo" =3D>=20
> "A102" } );
>=20
> print( %Vendors<< $x >><ContactName> ~ "\t" ~ %Vendors<< $x=20
>  >><AccountNo> ~ "\n" );
> <M/code>
>=20
>=20
> $ HashOfHashTest.pl6
> Mo=C2=A0=C2=A0=C2=A0 A102
>=20
> And it demanded a white space in << $x >>


And as Bruce pointed out, it should the %Vendors{$x}<ContactName>
0
perl6
1/11/2019 7:59:42 PM
On 1/11/19 11:59 AM, Bruce Gray wrote:
> That may work, but is bad practice.

no fooling!  look like hell too
0
perl6
1/11/2019 8:00:47 PM
Reply: