develooper Front page | perl.perl6.users | Postings from July 2021

Re: How do a pe-salt an array inside an object?

Thread Previous | Thread Next
Clifton Wood
July 13, 2021 04:06
Re: How do a pe-salt an array inside an object?
Message ID:
@ToddandMargo wrote:

Now I understand.  You are using Str as a
>      skip, skip, drop 2, skip, drop 4
> This is a sequential workaround.
> Also I was confused as I though Str was only
> a type declaration and could be used this way.
> What I would like to see is direct access, without the
> skips.
> In other words, the pre-salt equivalent of
> class AA { has Str @.I is rw };
> my $CC =;
> $CC.I[400]  = "four hundred"
> $CC.I[2000] = "two thousand"
> writing out 2000 skips is not practical.

I definitely agree with you, so let's use what we know of Raku to our
advantage. A hash structure would work well, here with the
Array-Indexes-to-Use as keys:

class AA {
  has @.I;

  submethod BUILD (:$data) {
     @!I[.key] = .value for $data[]

  method new (*@data) {
    self.bless( data => @data )

You can now do the following: => 'b', 4 => 66, 9 => 'apples')

Which makes for a nice initializer!

- X

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