GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
No::Worries::File(3) User Contributed Perl Documentation No::Worries::File(3)

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

  use No::Worries::File qw(file_read file_write file_update);

  # 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");

  # verbosely update a file
  file_update($path, data => "hello world", diff => 1);

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):
file_read(PATH[, OPTIONS])
read the file at the given path and return its contents; supported options:
  • "binary": treat the file as binary
  • "binmode": binary mode to use
  • "bufsize": buffer size to use for I/O operations
  • "data": return the file contents via this scalar reference or code reference
  • "handle": file handle to use
file_write(PATH[, OPTIONS])
write the given contents to the file at the given path; supported options:
  • "binary": treat the file as binary
  • "binmode": binary mode to use
  • "bufsize": buffer size to use for I/O operations
  • "data": provide the file contents via this scalar, scalar reference or code reference
  • "handle": file handle to use
file_update(PATH[, OPTIONS])
check the text file at the given path and update it if needed, printing what has been done on stdout; supported options:
  • "data": provide the file contents via this scalar
  • "diff": show differences
  • "noaction": do not update the file
  • "silent": do not print any message on stdout

Both file_read() and file_write() support a "handle" option that can contain a file handle to use. When given, this handle will be used (and closed at the end of the I/O operations) as is, without calling binmode() on it (see below).

These functions also support a "binary" option and a "binmode" option specifying how the file handle should be treated with respect to binmode().

If "binmode" is set, binmode() will be used with the given layer.

If "binmode" is not set but "binary" is true, binmode() will be used without any layer.

If neither "binmode" nor "binary" are set, 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 be written to the file.

file_update() only supports text files (no "binary" or "binmode" options) and the "data" option can only be a scalar.

This module uses the following global variables (none of them being exported):
$DefaultBufSize
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-2019

2021-10-15 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.