@@ -542,6 +542,35 @@ Unicode codepoint, and joining the characters.
542
542
543
543
This is the list-input version of L < chr > . The inverse operation is L < ords > .
544
544
545
+ = head2 routine split
546
+
547
+ multi method split( Str:D $delimiter, $limit = Inf, :$all)
548
+ multi method split(Regex:D $delimiter, $limit = Inf, :$all)
549
+ multi sub split( Str:D $delimiter, Str(Cool) $input, $limit = Inf, :$all)
550
+ multi sub split(Regex:D $delimiter, Str(Cool) $input, $limit = Inf, :$all)
551
+
552
+ Coerces the invocant (or in the sub form, the second argument) to
553
+ L < Str|/type/Str > , and splits it into pieces based on delimiters found in the
554
+ string.
555
+
556
+ If C < $delimiter > is a string, it is searched for literally and not treated
557
+ as a regex.
558
+
559
+ If the named parameter C < :all > is passed, the matches from C < $delimiter >
560
+ are included in the result list.
561
+
562
+ Note that unlike in Perl 5, empty chunks are not removed from the result list.
563
+ If you want that behavior, consider using L < comb > instead.
564
+
565
+ say split(';', "a;b;c").perl; # ("a", "b", "c").list
566
+ say split(';', "a;b;c", :all).perl; # ("a", ";", "b", ";", "c").list
567
+ say split(';', "a;b;c", 2).perl; # ("a", "b;c").list
568
+ say split(';', "a;b;c", 2, :all).perl; #("a", ";", "b;c").list
569
+
570
+ say split(';', "a;b;c,d").perl; # ("a", "b", "c,d").list
571
+ say split(/\;/, "a;b;c,d").perl; # ("a", "b", "c,d").list
572
+ say split(/<[;,]>/, "a;b;c,d").perl; # ("a", "b", "c", "d").list
573
+
545
574
= head2 method words
546
575
547
576
method words(Int() $limit)
@@ -570,7 +599,7 @@ Coerces the invocant to L<IO::Path>.
570
599
TODO: sech, asech, cosech, acosech, cotanh, acotanh, cis, roots, log10,
571
600
unpolar, truncate, fmt, substr-rw,
572
601
trans, index, rindex,
573
- split, match, comb, lines, subst, sprintf, printf, samecase,
602
+ match, comb, lines, subst, sprintf, printf, samecase,
574
603
EVAL
575
604
576
605
TODO: subroutine forms (where they exist)
0 commit comments