1File::Slurper(3) User Contributed Perl Documentation File::Slurper(3)
2
3
4
6 File::Slurper - A simple, sane and efficient module to slurp a file
7
9 version 0.012
10
12 use File::Slurper 'read_text';
13 my $content = read_text($filename);
14
16 This module provides functions for fast and correct slurping and
17 spewing. All functions are optionally exported. All functions throw
18 exceptions on errors, write functions don't return any meaningful
19 value.
20
22 read_text($filename, $encoding, $crlf)
23 Reads file $filename into a scalar and decodes it from $encoding (which
24 defaults to UTF-8). If $crlf is true, crlf translation is performed.
25 The default for this argument is off. The special value 'auto' will set
26 it to a platform specific default value.
27
28 read_binary($filename)
29 Reads file $filename into a scalar without any decoding or
30 transformation.
31
32 read_lines($filename, $encoding, $crlf, $skip_chomp)
33 Reads file $filename into a list/array line-by-line, after decoding
34 from $encoding, optional crlf translation and chomping.
35
36 write_text($filename, $content, $encoding, $crlf)
37 Writes $content to file $filename, encoding it to $encoding (which
38 defaults to UTF-8). It can also take a "crlf" argument that works
39 exactly as in read_text.
40
41 write_binary($filename, $content)
42 Writes $content to file $filename as binary data.
43
44 read_dir($dirname)
45 Open "dirname" and return all entries except "." and "..".
46
48 This module tries to make it as easy as possible to read and write
49 files correctly and fast. The most correct way of doing this is not
50 always obvious (e.g. #83126
51 <https://rt.cpan.org/Public/Bug/Display.html?id=83126>), and just as
52 often the most obvious correct way is not the fastest correct way. This
53 module hides away all such complications behind an easy intuitive
54 interface.
55
57 This module has an optional dependency on PerlIO::utf8_strict.
58 Installing this will make UTF-8 encoded IO significantly faster, but
59 should not otherwise affect the operation of this module. This may
60 change into a dependency on the related Unicode::UTF8 in the future.
61
63 • Path::Tiny
64
65 A minimalistic abstraction handling not only IO but also paths.
66
67 • IO::All
68
69 An attempt to expose as many IO related features as possible via a
70 single API.
71
72 • File::Slurp
73
74 This is a previous generation file slurping module. It has a number
75 of issues, as described here
76 <http://blogs.perl.org/users/leon_timmermans/2015/08/fileslurp-is-
77 broken-and-wrong.html>.
78
79 • File::Slurp::Tiny
80
81 This was my previous attempt at a better file slurping module. It's
82 mostly (but not entirely) a drop-in replacement for File::Slurp,
83 which is both a feature (easy conversion) and a bug (interface
84 issues).
85
87 • "open_text"/"open_binary"?
88
89 • "drain_handle"?
90
92 Leon Timmermans <leont@cpan.org>
93
95 This software is copyright (c) 2014 by Leon Timmermans.
96
97 This is free software; you can redistribute it and/or modify it under
98 the same terms as the Perl 5 programming language system itself.
99
100
101
102perl v5.32.1 2021-01-27 File::Slurper(3)