.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "File::Slurper 3pm" .TH File::Slurper 3pm "2023-01-08" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" File::Slurper \- A simple, sane and efficient module to slurp a file .SH "VERSION" .IX Header "VERSION" version 0.014 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use File::Slurper \*(Aqread_text\*(Aq; \& my $content = read_text($filename); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides functions for fast and correct slurping and spewing. All functions are optionally exported. All functions throw exceptions on errors, write functions don't return any meaningful value. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .ie n .SS "read_text($filename, $encoding, $crlf)" .el .SS "read_text($filename, \f(CW$encoding\fP, \f(CW$crlf\fP)" .IX Subsection "read_text($filename, $encoding, $crlf)" Reads file \f(CW$filename\fR into a scalar and decodes it from \f(CW$encoding\fR (which defaults to \s-1UTF\-8\s0). If \f(CW$crlf\fR is true, crlf translation is performed. The default for this argument is off. The special value \f(CW\*(Aqauto\*(Aq\fR will set it to a platform specific default value. .SS "read_binary($filename)" .IX Subsection "read_binary($filename)" Reads file \f(CW$filename\fR into a scalar without any decoding or transformation. .ie n .SS "read_lines($filename, $encoding, $crlf, $skip_chomp)" .el .SS "read_lines($filename, \f(CW$encoding\fP, \f(CW$crlf\fP, \f(CW$skip_chomp\fP)" .IX Subsection "read_lines($filename, $encoding, $crlf, $skip_chomp)" Reads file \f(CW$filename\fR into a list/array line-by-line, after decoding from \f(CW$encoding\fR, optional crlf translation and chomping. It will always use newline as separator. .ie n .SS "write_text($filename, $content, $encoding, $crlf)" .el .SS "write_text($filename, \f(CW$content\fP, \f(CW$encoding\fP, \f(CW$crlf\fP)" .IX Subsection "write_text($filename, $content, $encoding, $crlf)" Writes \f(CW$content\fR to file \f(CW$filename\fR, encoding it to \f(CW$encoding\fR (which defaults to \s-1UTF\-8\s0). It can also take a \f(CW\*(C`crlf\*(C'\fR argument that works exactly as in read_text. .ie n .SS "write_binary($filename, $content)" .el .SS "write_binary($filename, \f(CW$content\fP)" .IX Subsection "write_binary($filename, $content)" Writes \f(CW$content\fR to file \f(CW$filename\fR as binary data. .SS "read_dir($dirname)" .IX Subsection "read_dir($dirname)" Open \f(CW\*(C`dirname\*(C'\fR and return all entries except \f(CW\*(C`.\*(C'\fR and \f(CW\*(C`..\*(C'\fR. .SH "RATIONALE" .IX Header "RATIONALE" This module tries to make it as easy as possible to read and write files correctly and fast. The most correct way of doing this is not always obvious (e.g. #83126 ), and just as often the most obvious correct way is not the fastest correct way. This module hides away all such complications behind an easy intuitive interface. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" This module has an optional dependency on PerlIO::utf8_strict. Installing this will make \s-1UTF\-8\s0 encoded \s-1IO\s0 significantly faster, but should not otherwise affect the operation of this module. This may change into a dependency on the related Unicode::UTF8 in the future. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Path::Tiny .Sp A minimalistic abstraction handling not only \s-1IO\s0 but also paths. .IP "\(bu" 4 IO::All .Sp An attempt to expose as many \s-1IO\s0 related features as possible via a single \s-1API.\s0 .IP "\(bu" 4 File::Slurp .Sp This is a previous generation file slurping module. It has a number of issues, as described here . .IP "\(bu" 4 File::Slurp::Tiny .Sp This was my previous attempt at a better file slurping module. It's mostly (but not entirely) a drop-in replacement for File::Slurp, which is both a feature (easy conversion) and a bug (interface issues). .SH "TODO" .IX Header "TODO" .IP "\(bu" 4 \&\f(CW\*(C`open_text\*(C'\fR/\f(CW\*(C`open_binary\*(C'\fR? .IP "\(bu" 4 \&\f(CW\*(C`drain_handle\*(C'\fR? .SH "AUTHOR" .IX Header "AUTHOR" Leon Timmermans .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2014 by Leon Timmermans. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.