chomp
ErrorsCollection

chomp

Synthesised documentation from type/IO/Handle type/Allomorph type/Cool type/Str type/IO/CatHandle

From type/IO/Handle

See Original text in context

has $.chomp is rw = True

One of the attributes that can be set via .new or open. Defaults to True. Takes a Bool specifying whether the line separators (as defined by :$nl-in) should be removed from content when using .get or .lines methods.

From type/Allomorph

See Original text in context

method chomp(Allomorph:D:)

Calls Str.chomp on the invocant's Str value.

From type/Cool

See Original text in context

sub chomp(Str(Cool))
method chomp()

Coerces the invocant (or in sub form, its argument) to Str, and returns it with the last character removed, if it is a logical newline.

say 'ab'.chomp.chars;                   # OUTPUT: «2␤» 
say "a\n".chomp.chars;                  # OUTPUT: «1␤»

From type/Str

See Original text in context

multi sub    chomp(Str:D  --> Str:D)
multi method chomp(Str:D: --> Str:D)

Returns the string with a logical newline (any codepoint that has the NEWLINE property) removed from the end.

Examples:

say chomp("abc\n");       # OUTPUT: «abc␤» 
say "def\r\n".chomp;      # OUTPUT: «def␤» NOTE: \r\n is a single grapheme! 
say "foo\r".chomp;        # OUTPUT: «foo␤»

From type/IO/CatHandle

See Original text in context

method chomp(IO::CatHandle:D:is rw

Sets the invocant's $.chomp attribute to the assigned value. All source handles, including the active one will use the provided $.chomp value.

(my $f1 = 'foo'.IO).spurt: "A\nB\nC\n";
(my $f2 = 'bar'.IO).spurt: "D\nE\n";
with IO::CatHandle.new: $f1$f2 {
    # .chomp is True by default: 
    (.get xx 2).raku.say# OUTPUT: «("A", "B").Seq␤» 
 
    .chomp = False;
    (.get xx 3).raku.say# OUTPUT: «("C\n", "D\n", "E\n").Seq␤» 
    .close
}