No::Worries::File(3)

πŸ“¦
version 1.7 Β· 4 versions
, in epel 9

🌸 NAME 🌸

okay so this is No::Worries::File(3), hanging out under User Contributed Perl Documentation, and it is literally file handling without worries. It's giving β€œyour bestie wrapped the standard file functions so you can stop wrestling them by hand” energy. πŸ’–

✨ SYNOPSIS ✨

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

πŸ’… DESCRIPTION πŸ’…

This module makes file handling lowkey easy by giving you convenient wrappers around standard file functions. All the functions die() on error. No cap. 😭

πŸŽ€ FUNCTIONS πŸŽ€

This module provides the following functions β€” none of them are exported by default, so don't expect them to just show up in your namespace uninvited. πŸ™ˆ

πŸ“ file_read(PATH[, OPTIONS])

Reads the file at the given path and hands you 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])

Writes 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])

Checks the text file at the given path and updates 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.

πŸ¦‹ OPTIONS πŸ¦‹

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, bestie. πŸ’…

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. Periodt. πŸ’€

🌈 GLOBAL VARIABLES 🌈

This module uses the following global variables β€” none of them are exported:

  • $DefaultBufSize β€” default buffer size to use for I/O operations if not specified via the bufsize option (default: 1MB).

πŸ‘‘ SEE ALSO πŸ‘‘

  • No::Worries.

πŸ’– AUTHOR πŸ’–

Lionel Cons <http://cern.ch/lionel.cons>

Copyright (C) CERN 2012-2019


okay bestie, that's the whole No::Worries::File(3) vibe. This page is rocking perl v5.32.1, dated 2021-10-18 β€” now go handle those files with zero worries and main character energy πŸ’œβœ¨

πŸ“¦ where this page comes from