Help language development. Donate to The Perl Foundation
sub fold( $string, :$width where { ... } = 79 ) returns Str
Fold a string to contain no lines longer than the given width.
The string to fold.
The maximum width of lines in the text.
multi sub line-length( $ ) returns Int
Get the length of a line array. If the array does not exist yet, it is clearly empty, and this sub returns 0.
multi sub line-length( @line ) returns Int
Get the length of a line array. This counts the characters of all words in the array, and adds up the number of spaces required for it to be a human representable line.
The line array, containing any number of words.
String::Fold
Patrick Spek [email protected]
0.2.0
fold(Str:D $, Int:D :$width);
Fold a Str
to a given width. Accepts a :$width
Defaults to 79
argument.
use String::Fold;
my Str $folded = fold(slurp("some-text-file"));
This will yield a folded string in $folded
. The input file will have all its lines folded to a maximum width of 79 characters.
use String::Fold;
my Str $folded = slurp("some-text-file").&fold(:width(40));
This will yield a string folded at 40 characters, instead of the default of 79 characters. Any number higher than 0
is accepted.