Built-in routines

join / split / words / first

Full

Convert 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
5

Notes #