Methods by type
Splitting a string
FullBreak a string on a separator or regex, with a limit, :skip-empty, or into chunks.
.split breaks a string into a list on a separator, which can be a string or a regex, with an optional limit and the :skip-empty adverb. .comb is the complement — it keeps the pieces rather than the gaps.
Split on a string or regex #
say "a-b-c".split("-");
say "a1b2c".split(/\d/);
Output
(a b c)
(a b c)Limit the number of pieces #
A second argument caps the number of fields; the last one keeps the remainder.
say "a-b-c".split("-", 2);
Output
(a b-c)Drop empties with :skip-empty #
:skip-empty removes empty fields — such as the trailing empty left after a final separator.
say "a1b2c3".split(/\d/, :skip-empty);
Output
(a b c)comb into fixed-size chunks #
.comb(n) returns n-character chunks (the complement of splitting).
say "hello".comb(2);
Output
(he ll o)Notes #
.wordssplits on whitespace (dropping empty edges) and matches Rakudo — the right tool when the separator is "any run of spaces"..linessplits on line boundaries;.combwith no argument returns single characters (which matches Rakudo).- A regex separator lets you split on patterns:
.split(/\s* ',' \s*/)trims around commas.