No::Worries::File - file handling without worries
use No::Worries::File qw(file_read file_write); # read a file $data = file_read($path); # idem but with data returned by reference file_read($path, data => \$data); # write a file file_write($path, data => "hello world"); # idem but with data passed by reference file_write($path, data => \"hello world");
This module eases file handling by providing convenient wrappers around standard file functions. All the functions die() on error.
This module provides the following functions (none of them being exported by default):
read the file at the given path and return its contents; supported options:
binmode: binary mode to use (see below)
binmode
bufsize: buffer size to use for I/O operations
bufsize
data: return the file contents via this scalar reference or code reference (see below)
data
write the given contents to the file at the given path; supported options:
data: provide the file contents via this scalar, scalar reference or code reference (see below)
All the functions support a binmode option specifying how the file should be accessed:
binary: binmode(FH) will be used to treat the file as binary
binary
utf8: binmode(FH, ":encoding(utf8)") will be used to select UTF-8 encoding
utf8
otherwise: binmode() will not be used (this is the default)
file_read() can be given a code reference via the data option. Each time data is read via sysread(), the subroutine will be called with the read data. At the end of the file, the subroutine will be called with an empty string.
file_write() can be given a code reference via the data option. It should return data in a way similar to sysread(), returning an empty string to indicate the end of the data to write to the file.
This module uses the following global variables (none of them being exported):
default buffer size to use for I/O operations if not specified via the bufsize option (default: 1MB)
No::Worries.
Lionel Cons http://cern.ch/lionel.cons
Copyright (C) CERN 2012-2014
To install No::Worries, copy and paste the appropriate command in to your terminal.
cpanm
cpanm No::Worries
CPAN shell
perl -MCPAN -e shell install No::Worries
For more information on module installation, please visit the detailed CPAN module installation guide.