1No::Worries::File(3)  User Contributed Perl Documentation No::Worries::File(3)
2
3
4

NAME

6       No::Worries::File - file handling without worries
7

SYNOPSIS

9         use No::Worries::File qw(file_read file_write);
10
11         # read a file
12         $data = file_read($path);
13
14         # idem but with data returned by reference
15         file_read($path, data => \$data);
16
17         # write a file
18         file_write($path, data => "hello world");
19
20         # idem but with data passed by reference
21         file_write($path, data => \"hello world");
22

DESCRIPTION

24       This module eases file handling by providing convenient wrappers around
25       standard file functions. All the functions die() on error.
26

FUNCTIONS

28       This module provides the following functions (none of them being
29       exported by default):
30
31       file_read(PATH[, OPTIONS])
32           read the file at the given path and return its contents; supported
33           options:
34
35           ·   "binary": treat the file as binary
36
37           ·   "binmode": binary mode to use
38
39           ·   "bufsize": buffer size to use for I/O operations
40
41           ·   "data": return the file contents via this scalar reference or
42               code reference
43
44           ·   "handle": file handle to use
45
46       file_write(PATH[, OPTIONS])
47           write the given contents to the file at the given path; supported
48           options:
49
50           ·   "binary": treat the file as binary
51
52           ·   "binmode": binary mode to use
53
54           ·   "bufsize": buffer size to use for I/O operations
55
56           ·   "data": provide the file contents via this scalar, scalar
57               reference or code reference
58
59           ·   "handle": file handle to use
60

OPTIONS

62       Both functions support a "handle" option that can contain a file handle
63       to use. When given, this handle will be used (and closed at the end of
64       the I/O operations) as is, without calling binmode() on it (see below).
65
66       These functions also support a "binary" option and a "binmode" option
67       specifying how the file handle should be treated with respect to
68       binmode().
69
70       If "binmode" is set, binmode() will be used with the given layer.
71
72       If "binmode" is not set but "binary" is true, binmode() will be used
73       without any layer.
74
75       If neither "binmode" nor "binary" are set, binmode() will not be used.
76       This is the default.
77
78       file_read() can be given a code reference via the "data" option. Each
79       time data is read via sysread(), the subroutine will be called with the
80       read data.  At the end of the file, the subroutine will be called with
81       an empty string.
82
83       file_write() can be given a code reference via the "data" option. It
84       should return data in a way similar to sysread(), returning an empty
85       string to indicate the end of the data to be written to the file.
86

GLOBAL VARIABLES

88       This module uses the following global variables (none of them being
89       exported):
90
91       $DefaultBufSize
92           default buffer size to use for I/O operations if not specified via
93           the "bufsize" option (default: 1MB)
94

SEE ALSO

96       No::Worries.
97

AUTHOR

99       Lionel Cons <http://cern.ch/lionel.cons>
100
101       Copyright (C) CERN 2012-2017
102
103
104
105perl v5.28.0                      2017-08-01              No::Worries::File(3)
Impressum