--- name: split status: documented runtime: pp source: src/runtime/pp/regex/split.rs --- ```{index} single: split; Perl built-in (pp runtime) ``` # split ## Synopsis ```perl @fields = split /PATTERN/, EXPR, LIMIT; @fields = split /PATTERN/, EXPR; @fields = split /PATTERN/; # splits $_ @fields = split ' ', $string; # awk-style split my $count = split /,/, $csv; # scalar context: count ``` ## Description Splits a string into a list of substrings using a pattern. Splits EXPR (or `$_` if omitted) into substrings at each match of PATTERN. If LIMIT is positive, returns at most LIMIT fields. If LIMIT is negative, behaves as if arbitrarily large. If LIMIT is zero or omitted (default), trailing empty fields are stripped. Special case: `split ' '` (with `pmflags & 0x800`) uses awk-style semantics -- splits on runs of whitespace and ignores leading whitespace. An empty pattern (`split //, $str`) splits every character. If a `split_targ` is set in the op, results are stored directly into the target array (pad slot) instead of the stack. In scalar context, returns the number of fields. ## See also join, m//g, perlre