develooper Front page | perl.perl6.users | Postings from March 2020

stashing an array in a hash and yanking it back out

Thread Next
Joseph Brenner
March 5, 2020 03:36
stashing an array in a hash and yanking it back out
Message ID:
There might not be much to say about this, I just though I'd
mention that I keep getting re-surprised by basics with Raku,
like this one, where first I stash an array away in a hash and
later try to pull the array out again:

    my %stash;
    my @monsters =
      << godzilla grendel wormface blob fingfangfoom tingler >>;
    %stash{'monsters'} = @monsters;

Now some time later, when I wanted to extract that array again,
my first thought was to do this:

    my @m = %stash{'monsters'};

But that doesn't get the original array back, instead you end up
with the entire original array as the first element of a newly
created array:

    # [[godzilla grendel wormface blob fingfangfoom tingler]]

Yary Hluchan pointed out that I could slip it out, and get what
I wanted:

    my @m = | %stash{'monsters'};
    say @m;
    # [godzilla grendel wormface blob fingfangfoom tingler]

Though for what I'm doing now, I think it might be better to
just alias it with the binding operator:

   my @m := %stash{'monsters'};

So, like I said: I don't have any particular questions about this,
I think I more or less know what's going on... it will be a while
before I stop tripping over this sort of thing, though.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About