File::...nicode(3pm)
π NAME π
File::Slurp::Unicode β bestie, this is your reading/writing of complete files but with character encoding support on top. Yes, it's giving finally. β¨
π¦ SYNOPSIS π¦
use File::Slurp::Unicode;
my $text = read_file('filename', encoding => 'utf8');
my @lines = read_file('filename'); # utf8 is assumed if no encoding.
write_file('filename', { encoding => 'utf16' }, @lines);
# same as File::Slurp::write_file (ie. no encoding):
write_file('filename', { encoding => 'binary' }, @lines);
use File::Slurp::Unicode qw(slurp);
my $text = slurp('filename', encoding => 'latin1');
Like. Look at that. So clean. So effortless. π
πΈ DESCRIPTION πΈ
Okay so here's the tea, bestie: this module wraps File::Slurp and adds character encoding support via the encoding parameter. That's it. That's the whole personality.
It exports the exact same functions, and those functions take all the same parameters as File::Slurp. So if you wanna know the basics, go read the File::Slurp documentation β from here on out we're only talking about the differences. No cap. π«Ά
π read_file
Pass in an argument called encoding to change the file encoding. If you pass in no argument at all, then UTF-8 encoding is assumed. The default is just that girl. π
The special encoding 'binary' means "there should be no decoding done to the data after reading it." This is pretty much the same as calling File::Slurp::read_file() directly. The only reason this option exists is so code that needs to read both binary and text files can look uniform. Aesthetic consistency, we love to see it. β¨
βοΈ write_file
Pass in an argument called encoding to change the file encoding. If you pass in no argument and there are no wide characters present in the output data, then no conversion will be done. But if there are wide characters in the output data, then UTF-8 encoding is assumed. It reads the room. π₯
The special encoding 'binary' means "there should be no encoding done to the data before writing."
π¨ Okay listen up because this one matters: if you pass a wide string (a string with Perl's internal'utf8 bit'set) towrite_fileand set the encoding to'binary', it will die with an appropriate message. It's not being dramatic, it's being honest. π
This is pretty much the same as calling File::Slurp::write_file() directly. And again, this option is here only so code that needs to write both binary and text files can look uniform. Slay. π
π SEE ALSO π
File::Slurp
π BUGS π
None known. Contact the author or file a bug report on CPAN if you find any. Like, if you catch something, say something β bestie to bestie. π
Β©οΈ COPYRIGHT Β©οΈ
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Copyright (C) 2010 David Caldwell
π AUTHOR π
David Caldwell <david@porkrind.org>
π PROJECT HOME π
<http://github.com/caldwell/File-Slurp-Unicode>
And that's a wrap on the File::Slurp::Unicode manual page, which lives in the perl v5.36.0 docs and was last touched on 2022-11-27. Go read a whole file with the right encoding, you icon. ππ
π¦ where this page comes from
- debian bookworm: libfile-slurp-unicode-perl 0.7.1-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libfile-slurp-unicode-perl 0.7.1-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libfile-slurp-unicode-perl 0.7.1-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-slurp-unicode-perl 0.7.1-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-slurp-unicode-perl 0.7.1-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms