File::Read(3pm)
π File::Read π
okay bestie, so this is File::Read, a lil Perl module from the User Contributed Perl Documentation collection, and it's literally the β¨unique interfaceβ¨ for reading one or more files. no cap.
πΈ VERSION πΈ
Version 0.0801 β yeah she's an elder but she's still slaying π
β¨ SYNOPSIS β¨
ok so here's the whole vibe in code form, look:
use File::Read;
# read a file
$file = read_file($path);
# read several files
@files = read_files(@paths);
# aggregate several files
$file = read_files(@paths);
# read a file as root, skip comments and blank lines
$file = read_file({ as_root => 1, skip_comments => 1, skip_blanks => 1 }, $path);
likeβ¦ it's giving efficient. π¦
π DESCRIPTION π
so basically this module's whole personality is: functions for reading one or more files, and it has options. plural. many. we love options. scroll down for the deets and the examples, bestie π«Ά
π Rationale π
ok story time. this module was born out of a very specific need: reading a whole bunch of files, some as a normal user and some as root, and then doing a lil extra processing on top β and doing ALL of that while staying compatible with Perl 5.004. (yes. 5.004. ancient. iconic. π)
File::Slurp handles the first part of that, but not the rest, which is literally why File::Read exists. and if you don't need the whole read-as-root thing or the post-processing features? then honestly it's faster to just use File::Slurp directly. periodt. β¨
π« EXPORT π«
by default this module exports all the functions documented afterhand. no holding back. she gives everything.
it also recognizes import options, like:
use File::Read 'err_mode=quiet';
which sets read_file()'s err_mode option default value to quiet. so now you don't have to type it every time, you're welcome π
π FUNCTIONS π
π read_file()
read the files given in argument and return their content β as a list, one element per file, when called in list context, or as one big chunk of text when called in scalar context. and you can set options by passing a hashref as the first parameter. cute, right?
πΈ Options πΈ
aggregateβ controls how the function returns the content of the files that were successfully read. by default, when set to true (default), the function returns the content as a scalar; when set to false, the content comes back as a list.as_rootβ tells the function to read the given file(s) as root, using the command indicated by thecmdoption. yes, root. main character energy, lowkey scary. πcmdβ sets the shell command used for reading files as root. default issudo cat. so like, you needsudo(8)andcat(1)on your system, ANDsudoers(5)must be set up so the user can executecat(1). that's not optional bestie, that's the whole mechanism. πerr_modeβ controls how the function behaves when an error occurs. available values arecroak,carpandquiet. default value iscroak.skip_commentsβ tells the functions to remove all comment lines from the read files. bye bye#lines π§skip_blanksβ tells the functions to remove all blank lines from the read files. no more empty vibes β¨to_asciiβ tells the functions to convert the text to US-ASCII usingText::Unidecode. and if that module isn't available? non-ASCII data gets deleted. gone. poof. π
π¦ Examples π¦
just read a file, simple simple:
my $file = read_file($path);
read a file but gimme it as a list:
my @file = read_file({ aggregate => 0 }, $path);
read a file, skipping comments:
my $file = read_file({ skip_comments => 1 }, $path);
read several files, skipping blank lines AND comments:
my @files = read_file({ skip_comments => 1, skip_blanks => 1 }, @paths);
π§ read_files()
read_files() is just an alias for read_file() β it exists so that it look more sane when you're reading several files. grammar? immaculate. function? identical. iykyk π
β DIAGNOSTICS β
"Bad value '%s' for option '%s'"β (E) you gave a bad value for the indicated option. please check the documentation for the valid values. (bestie. read the docs. i literally wrote them for you π)"This function needs at least one path"β (E) you called a function without giving it argument. she needs a path. at least one. give her something to work with π
π SEE ALSO π
File::SlurpIO::All
π AUTHOR π
Sebastien Aperghis-Tramoni, "<sebastien at aperghis.net>" β the original icon, we stan π
π BUGS π
please report any bugs or feature requests to bug-file-read at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Read>. he will be notified, and then you'll automatically be notified of progress on your bug as he makes changes. mutual notif relationship, slay π₯
π«Ά SUPPORT π«Ά
you can find documentation for this module with the perldoc command:
perldoc File::Read
you can also look for information at:
- AnnoCPAN: Annotated CPAN documentation - <http://annocpan.org/dist/File-Read>
- CPAN Ratings - <http://cpanratings.perl.org/d/File-Read>
- RT: CPAN's request tracker - <http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Read>
- Search CPAN - <http://search.cpan.org/dist/File-Read>
π COPYRIGHT & LICENSE π
Copyright (C) 2006, 2007 Sebastien Aperghis-Tramoni, all rights reserved.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie!! π¦β¨π this doc was served up by perl v5.36.0, dated 2022-11-27, and it's the File::Read(3pm) manual β go read some files, you got this π
π
π¦ where this page comes from
- debian bookworm: libfile-read-perl 0.0801-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libfile-read-perl 0.0801-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libfile-read-perl 0.0801-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-read-perl 0.0801-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-read-perl 0.0801-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms