Built-in routines
join / split / words / first
FullConvert between strings and lists, and pluck the first matching element.
These routines bridge strings and lists: split and words break a string apart, join puts a list back together, and first returns the earliest element matching a test.
join and split #
join glues a list into a string with a separator; split is the inverse.
say <a b c>.join("-");
say "a,b,c".split(",");
Output
a-b-c
(a b c)words #
words splits on runs of whitespace, ignoring leading and trailing space — the right tool for tokenising text.
say "the quick fox".words;
Output
(the quick fox)first #
first returns the earliest element for which the block is true (not the index).
say (1..10).first(* > 4);
Output
5Notes #
splitreturns aSeq;joinalways returns aStr.splitcan also take a regex, and:skip-emptydrops empty fields.wordsis roughlysplit(/\s+/)with the empty edges removed; use it in preference when you just want the non-space chunks.- Related pluckers:
first(element),first(:k, …)(its key/index), andgrep(all matches instead of just the first).