Encode::Newlines(3)
π Encode::Newlines β the line-ending glow-up module π
okay bestie, so this is a User Contributed Perl Documentation page for a lil module called Encode::Newlines β and no cap, it's the friend who fixes your messy line endings for you. β¨
π NAME π
Encode::Newlines β it normalizes line ending sequences. that's the whole job. iconic.
πΈ VERSION πΈ
This doc describes version 0.04 of Encode::Newlines, and it was released September 4, 2007. yes she's vintage. vintage is a vibe. π¦
β¨ SYNOPSIS β¨
use Encode;
use Encode::Newlines;
# Convert to native newlines
# Note that decode() and encode() are equivalent here
$native = decode(Native => $string);
$native = encode(Native => $string);
{
# Allow mixed newlines in $mixed
local $Encode::Newlines::AllowMixed = 1;
$cr = encode(CR => $mixed);
}
like, look at her go. decode and encode are literally the same thing here β that's not a typo, that's the design. π
π DESCRIPTION π
so this module hands you the CR, LF, CRLF and Native encodings, all so you can normalize your line endings without losing your mind. π«Ά
It takes whatever line endings your source is using and converts them into the newline sequence you asked for β and it does this for both encode and decode operations. equal opportunity icon. π
Now here's the spicy part: if you specify two different line endings joined by a -, it uses the first one for decoding and the second one for encoding. so the LF-CRLF encoding means all your input gets normalized to LF, and all your output gets normalized to CRLF. it's giving translator. it's giving bilingual. π
And if the source has an inconsistent line ending style? π Then a "Mixed newlines" exception gets raised on behalf of the caller. rude but fair. BUT β if the package variable $Encode::Newlines::AllowMixed is set to a true value, then it'll silently convert all three line endings. no drama, no exception, just vibes. β¨
π¨ CAVEATS π¨
bestie. listen. this one matters.
This module is not suited for working with PerlIO::encoding, because it cannot guarantee that the chunk boundaries won't happen within a CR/LF sequence. that's the whole problem, that's the whole reason. π
If you want to know how to deal with this correctly, go look at PerlIO::eol. she's the one who actually knows what she's doing. π§
Also, an optional XS implementation would be nice. yeah. manifesting that for her. π
π AUTHORS π
Audrey Tang <audreyt@audreyt.org>
π COPYRIGHT AND LICENSE π
Copyright 2004-2007 by Audrey Tang <audreyt@audreyt.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>
and that's the whole page, bestie β you ate it, you read it, you understood it. periodt. π β¨
oh also, tiny sign-off moment: this page came from perl v5.42.0, dated 2025-07-25, and yeah, it's Encode::Newlines(3). take care of your line endings and they'll take care of you. ππ
π¦ where this page comes from
- fedora 43: perl-Encode-Newlines 0.05-28.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms