Documentation for routine lines
Documentation for routine lines, assembled from the following types:
sub lines(Str(Cool))method lines()
Coerces the invocant (and in sub form, the argument) to Str, decomposes it into lines (with the newline characters stripped), and returns the list of lines.
say lines("a\nb\n").join('|'); # OUTPUT: «a|b␤»say "some\nmore\nlines".lines.elems; # OUTPUT: «3␤»
This method can be used as part of an
IO::Path to process a file line-by-line, since
IO::Path objects inherit from
for 'huge-csv'.IO.lines -># or if you'll be processing latermy = 'huge-csv'.IO.lines;
Without any arguments, sub
lines operates on
$*ARGFILES, which defaults to
$*IN in the absence of any filenames.
To modify values in place use
is copy to force a writable container.
for .lines -> is copy
multi sub lines(Str , = Inf --> Positional)multi method lines(Str : = Inf --> Positional)
Returns a list of lines (without trailing newline characters), i.e. the same as a call to
$input.comb( / ^^ \N* /, $limit ) would.
say lines("a\nb").perl; # OUTPUT: «("a", "b").Seq␤»say lines("a\nb").elems; # OUTPUT: «2␤»say "a\nb".lines.elems; # OUTPUT: «2␤»say "a\n".lines.elems; # OUTPUT: «1␤»
method lines( = Inf)
Return a lazy list of the file's lines read via get, limited to
$limit lines. The new line separator (i.e.,
$*IN.nl-in) will be excluded.
my ;my = open 'readings.csv';for .lines ->
Return a (lazy) list of the remaining lines in the file pointed to by the file handle.
Returns a lazy list of lines read from the socket.
method lines(Supply: : = True --> Supply)
Creates a supply that will emit the characters coming in line by line from a supply that's usually created by some asynchronous I/O operation. The optional :chomp parameter indicates whether to remove line separators: the default is True.