routine comb
1 | class Str |
1.1 | (Str) routine comb |
2 | class Cool |
2.1 | (Cool) routine comb |
3 | class IO::CatHandle |
3.1 | (IO::CatHandle) method comb |
4 | class IO::Path |
4.1 | (IO::Path) method comb |
5 | class IO::Handle |
5.1 | (IO::Handle) method comb |
Documentation for routine comb
assembled from the following types:
class Str
From Str
(Str) routine comb
multi sub comb(Str , Str , = Inf)multi sub comb(Regex , Str , = Inf, Bool :)multi sub comb(Int , Str , = Inf)multi method comb(Str :)multi method comb(Str : Str , = Inf)multi method comb(Str : Regex , = Inf, Bool :)multi method comb(Str : Int , = Inf)
Searches for $matcher
in $input
and returns a Seq of non-overlapping matches limited to at most $limit
matches. If $matcher
is a Regex, each Match
object is converted to a Str
, unless $match
is set.
If no matcher is supplied, a Seq of characters in the string is returned, as if the matcher was rx/./
.
Examples:
say "abc".comb.perl; # OUTPUT: «("a", "b", "c").Seq»say "abc".comb(:match).perl; # OUTPUT: «(「a」 「b」 「c」)»say 'abcdefghijk'.comb(3).perl; # OUTPUT: «("abc", "def", "ghi", "jk").Seq»say 'abcdefghijk'.comb(3, 2).perl; # OUTPUT: «("abc", "def").Seq»say comb(/\w/, "a;b;c").perl; # OUTPUT: «("a", "b", "c").Seq»say comb(/\N/, "a;b;c").perl; # OUTPUT: «("a", ";", "b", ";", "c").Seq»say comb(/\w/, "a;b;c", 2).perl; # OUTPUT: «("a", "b").Seq»say comb(/\w\;\w/, "a;b;c", 2).perl; # OUTPUT: «("a;b",).Seq»say comb(/.<(.)>/, "<>[]()").perl; # OUTPUT: «(">", "]", ")").Seq»
If the matcher is an integer value, comb
behaves as if the matcher was rx/ . ** {1..$matcher} /
, but which is optimized to be much faster.
Note that a Regex matcher may control which portion of the matched text is returned by using features which explicitly set the top-level capture.
class Cool
From Cool
(Cool) routine comb
Defined as:
multi sub comb(Regex , Cool , = *)multi sub comb(Str , Cool , = *)multi sub comb(Int , Cool , = *)multi method comb(|c)
Returns a Seq of all (or if supplied, at most $limit
) matches of the invocant (method form) or the second argument (sub form) against the Regex, string or defined number.
say "6 or 12".comb(/\d+/).join(", "); # OUTPUT: «6, 12»say comb(/\d /,(11..30)).join("--");# OUTPUT:# «11--12--13--14--15--16--17--18--19--21--22--23--24--25--26--27--28--29»
The second statement exemplifies the first form of comb
, with a Regex
that excludes multiples of ten, and a Range
(which is Cool
) as $input
. comb
stringifies the Range
before applying .comb
on the resulting string. Check Str.comb
for its effect on different kind of input strings. When the first argument is an integer, it indicates the (maximum) size of the chunks the input is going to be divided in
say comb(3,[3,33,333,3333]).join("*"); # OUTPUT: «3 3*3 3*33 *333*3»
In this case the input is a list, which after transformation to Str
(which includes the spaces) is divided in chunks of size 3.
class IO::CatHandle
From IO::CatHandle
(IO::CatHandle) method comb
Defined as:
method comb(IO::CatHandle: |args --> Seq)
Read the handle and processes its contents the same way Str.comb
does, taking the same arguments. Implementations may slurp the contents of all the source handles in their entirety when this method is called.
(my = 'foo'.IO).spurt: 'foo';(my = 'bar'.IO).spurt: 'bar';IO::CatHandle.new(, ).comb(2).perl.say;# OUTPUT: «("fo", "ob", "ar").Seq»
class IO::Path
From IO::Path
(IO::Path) method comb
Defined as:
method comb(IO::Path: |args --> Seq)
Opens the file and processes its contents the same way Str.comb
does, taking the same arguments. Implementations may slurp the file in its entirety when this method is called.
class IO::Handle
From IO::Handle
(IO::Handle) method comb
Defined as:
method comb(IO::Handle: Bool :, |args --> Seq)
Read the handle and processes its contents the same way Str.comb
does, taking the same arguments, closing the handle when done if $close
is set to a true value. Implementations may slurp the file in its entirety when this method is called.
Attempting to call this method when the handle is in binary mode will result in X::IO::BinaryMode
exception being thrown.
my = 'path/to/file'.IO.open;say "The file has ♥s in it";