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

NAME

6       File::LoadLines - Load lines from file
7

SYNOPSIS

9           use File::LoadLines;
10
11           my @lines = loadlines("mydata.txt");
12           ...
13

DESCRIPTION

15       File::LoadLines provides an easy way to load the contents of a text
16       file into an array of lines. It is intended for relatively small files
17       like config files that are often produced by weird tools (and users).
18
19       It automatically handles ASCII, Latin-1 and UTF-8 text.  When the file
20       has a BOM, it handles UTF-8, UTF-16 LE and BE, and UTF-32 LE and BE.
21
22       Recognized line terminators are NL (Unix, Linux), CRLF (DOS, Windows)
23       and CR (Mac)
24

EXPORT

26   loadlines

FUNCTIONS

28   loadlines
29           my @lines = loadlines("mydata.txt");
30           my @lines = loadlines("mydata.txt", $options);
31
32       Basically, the file is opened, read, decoded and split into lines that
33       are returned in the result array. Line terminators are removed.
34
35       In scalar context, returns an array reference.
36
37       The first argument may be the name of a file, an opened file handle, or
38       a reference to a string that contains the data.
39
40       The second argument can be used to influence the behaviour.  It is a
41       hash reference of option settings.
42
43       Note that loadlines() is a slurper, it reads the whole file into memory
44       and requires temporarily memory for twice the size of the file.
45
46       split
47           Enabled by default.
48
49           If set to zero, the data is not split into lines but returned as a
50           single string.
51
52       chomp
53           Enabled by default.
54
55           If set to zero, the line terminators are not removed from the
56           resultant lines.
57
58       encoding
59           If specified, loadlines() will use this encoding to decode the file
60           data if it cannot automatically detect the encoding.
61
62           If you pass an options hash, File::LoadLines will set "encoding" to
63           the encoding it detected and used for this file data.
64

SEE ALSO

66       There are currently no other modules that handle BOM detection and line
67       splitting.
68
69       I have a faint hope that future versions of Perl and Raku will deal
70       with this transparently, but I fear the worst.
71

HINTS

73       When you have raw file data (e.g. from a zip), you can use loadlines()
74       to decode and unpack:
75
76           open( my $data, '<', \$contents );
77           $lines = loadlines( $data, $options );
78

AUTHOR

80       Johan Vromans, "<JV at cpan.org>"
81

SUPPORT AND DOCUMENTATION

83       Development of this module takes place on GitHub:
84       https://github.com/sciurius/perl-File-LoadLines.
85
86       You can find documentation for this module with the perldoc command.
87
88           perldoc File::LoadLines
89
90       Please report any bugs or feature requests using the issue tracker on
91       GitHub.
92
94       Copyright 2018,2020 Johan Vromans, all rights reserved.
95
96       This program is free software; you can redistribute it and/or modify it
97       under the same terms as Perl itself.
98
99
100
101perl v5.34.0                      2022-01-21                File::LoadLines(3)
Impressum