Help language development. Donate to The Perl Foundation

Text::Utils cpan:TBROWDER last updated on 2020-04-06


Build Status


This module provides some miscellaneous text processing routines not provided by core Raku. (Note it replaces the now-deprecated Text::More module.)

Note this introduces a new API 2 for the strip-comment routine. See the examples below for its use. The old signature is still usable, but it is deprecated and will be removed in version 3.0.0.


use Text::Utils :ALL;

Note that individual subroutines may also be exported:

use Text::Utils :strip-comment;
# the '#' is the default comment character
my $line = " some  text # a comment";
$line = strip-comment $line;
say $line; # OUTPUT: « some  text ␤»

If you want to be fancier, return the stripped line and its comment, with both strings normalized (trimmed of leading and trailing spaces, contiguous spaces collapsed to one):

# define your own comment character(s)
# save the comment and normalize the returned strings
my ($line, $comm) = strip-comment $line, :mark<%%>, :save-comment, :normalize;
say $line; # OUTPUT: «some text␤»
say $comm; # OUTPUT: «a comment␤»

The default behavior is to find the first comment character in the input string, but you may choose to start the search from the end of the input string:

my $line = "text 1 # text 2 # comment";
$line = strip-comment $line, :reverse;
say $line; # OUTPUT: «text 1 # text 2 ␤»

Note that the routine is line oriented, so embedded newlines may give unexpected results:

my $line = q:to/HERE/;
text 1 # comment 1
text 2 # comment 2
$line = strip-comment $line
say $line; # OUTPUT: «text 1 ␤»


zef install Text::Utils


zef install p6doc
p6doc Text::Utils

See also


The commify subroutine is based on the subroutine of the same name found in the Perl Cookbook.


Artistic 2.0. See that license here.

Copyright (C) 2019 Thomas M. Browder, Jr. <[email protected]>