File::Slurper(3pm)

File::Slurper3pm

A simple, sane and efficient module to slurp a file

Usage

 use File::Slurper 'read_text';
 my $content = read_text($filename);

Version

version 0.014

Overview

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.

Functions

read_text($filename, $encoding, $crlf)

Reads file $filename into a scalar and decodes it from $encoding (which defaults to UTF-8). If $crlf is true, crlf translation is performed. The default for this argument is off. The special value 'auto' will set it to a platform specific default value.

read_binary($filename)

Reads file $filename into a scalar without any decoding or transformation.

read_lines($filename, $encoding, $crlf, $skip_chomp)

Reads file $filename into a list/array line-by-line, after decoding from $encoding, optional crlf translation and chomping. It will always use newline as separator.

write_text($filename, $content, $encoding, $crlf)

Writes $content to file $filename, encoding it to $encoding (which defaults to UTF-8). It can also take a "crlf" argument that works exactly as in read_text.

write_binary($filename, $content)

Writes $content to file $filename as binary data.

read_dir($dirname)

Open "dirname" and return all entries except "." and "..".

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 <https://rt.cpan.org/Public/Bug/Display.html?id=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.

Dependencies

This module has an optional dependency on PerlIO::utf8_strict. Installing this will make UTF-8 encoded IO 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.

Todo

•

"open_text"/"open_binary"?

•

"drain_handle"?

Releases

6 releases since Debian 9 (Stretch); the text changed 3 times.

  1. 9
  2. 10–11
  3. 12–13
  4. Arch

Author

Leon Timmermans <[email protected]>

From perl-file-slurper 0.014-6 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.