This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =begin pod | |
| =head2 routine split | |
| Definded as: | |
| multi sub split( Str:D $delimiter, Str:D $input, $limit = Inf, :$all) returns Positional | |
| multi sub split(Regex:D $delimiter, Str:D $input, $limit = Inf, :$all) returns Positional | |
| multi method split(Str:D $input: Str:D $delimiter, $limit = Inf, :$all) returns Positional | |
| multi method split(Str:D $input: Regex:D $delimiter, $limit = Inf, :$all) returns Positional | |
| Usage: | |
| split( DELIMITER, EXPR [, LIMIT] [, :all]) | |
| split( PATTERN, EXPR [, LIMIT] [, :all]) | |
| EXPR.split( DELIMITER [, LIMIT] [, :all]) | |
| EXPR.split( PATTERN [, LIMIT] [, :all]) | |
| Splits a string up into pieces based on delimiters found in the string. | |
| If C<$delimiter> is a string, it is searched for literally and not treated | |
| as a regex. | |
| If the named parameter C<:all> is passed, the matches from C<$delimiter> | |
| are included in the result list. | |
| Note that unlike in Perl 5, empty chunks are not removed from the result list. | |
| If you want that behavior, consider using L<comb> instead. | |
| Examples: | |
| =begin code | |
| say split(';', "a;b;c").perl; # ("a", "b", "c").list | |
| say split(';', "a;b;c", :all).perl; # (("a", ";"), ("b", ";"), "c").list | |
| say split(';', "a;b;c", 2).perl; # ("a", "b;c").list | |
| say split(';', "a;b;c", 2, :all).perl; # (("a", ";"), "b;c").list | |
| say split(';', "a;b;c,d").perl; # ("a", "b", "c,d").list | |
| say split(/\;/, "a;b;c,d").perl; # ("a", "b", "c,d").list | |
| say split(/<[;,]>/, "a;b;c,d").perl; # ("a", "b", "c", "d").list | |
| =end code | |
| =end pod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment