Encode::Newlines(3)

πŸ“¦
version 0.05 Β· 3 versions
, in fedora 43

πŸ’– 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 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