Hi Timo and thank you for the note.

Yes, since I was working in the REPL, I tried compacting Joe's code by
eliminating the "my %stash" line at the top, and adding "my" to the third
line.
I figured since Joe's code looked like a closure (curly brackets and all),
it wouldn't be an issue.
But the two runs through the REPL below give wildly different results:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my %stash
{}
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> %stash{'monsters'} = @monsters;
[godzilla grendel wormface blob fingfangfoom tingler]
>
> exit
mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my %stash{'monsters'} = @monsters;
{fingfangfoom => tingler, godzilla => grendel, wormface => blob}
>

>From Liz's note it seems to me the correct way to do this is:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>
> .say for %stash<monsters>;
[godzilla grendel wormface blob fingfangfoom tingler]
> %stash<monsters>.say
[godzilla grendel wormface blob fingfangfoom tingler]
>

Thanks again, Bill.




On Thu, Mar 5, 2020 at 12:33 AM Timo Paulssen <t...@wakelift.de> wrote:

>
> Hi William,
>
> The line that has the important difference is where you put a `my` in
> front of `%stash{'monsters'} = @monsters`. Probably a copy-paste error or
> something like that.
>
> >> my %stash > {} >> my @monsters = <<godzilla grendel wormface blob
> fingfangfoom >> tingler >> > [godzilla grendel wormface blob fingfangfoom
> tingler] >> my %stash{'monsters'} = @monsters; > {fingfangfoom =>
> tingler, godzilla => grendel, wormface => blob} >> my @m =
> %stash{'monsters'}; > [(Any)] >> say @m > [(Any)] >> exit
>
> timo@schmand ~> perl6 -e 'my %stash{"monsters"} = :1a; dd %stash'
> Hash[Any,Str] %stash = (my Any %{Str} = :a(1))
> timo@schmand ~> perl6 -e 'my %stash; %stash{"monsters"} = :1a; dd %stash'
> Hash %stash = {:monsters(:a(1))}
>
> Here you can see that in the case of having a "my" in front, the assigned
> data doesn't get put in the hash at the "monsters" key. instead, it gets
> assigned to the whole hash. The reason for that is that `my %foo{Bar}` is
> syntax for restricting the keys of the hash to a specific type (by default
> it's `Str(Any)`) and giving a string instance ("monsters" in this case)
> just takes the type of the value.
>
> Hope that clears things up
>   - Timo
>

Reply via email to