On Wed, Sep 26, 2018 at 6:13 PM Brandon Allbery <allber...@gmail.com> wrote:
> On Wed, Sep 26, 2018 at 6:09 PM ToddAndMargo <toddandma...@zoho.com> > wrote: > >> multi method words(Str:D $input: $limit = Inf --> Positional) >> > "a b c d".words(3); (a b c) passing the $limit parameter in with 3, limits the number of words returned to 3. "a b c d".words(2); (a b) Passing a $limit of 2, limits the words returned to 2. If you *don't* set $limit at all, it gets set to its default, Inf, or all the words. It just never stops because there is no limit. "a b c d".words(); (a b c d) The () are optional since you aren't passing in any parameters, so you can also just say "a b c d".words; (a b c d) You can store that in a variable my @x = "a b c d".words; Once you've got that in a variable, as described in detail on the page about Positional, you can access parts of it with the [] operator, for example, the word in the '2' position (the third word counting from 0) is @x[2] c What looks a little weird is that you don't need @x at all. You can just call the [] operator directly on the return value from words "a b c d".words()[2] c and of course, you can omit the () since you aren't passing in parameters, so this is the same thing "a b c d".words[2] c Curt