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
File::LoadLines(3) User Contributed Perl Documentation File::LoadLines(3)

File::LoadLines - Load lines from file

    use File::LoadLines;

    my @lines = loadlines("mydata.txt");
    ...

File::LoadLines provides an easy way to load the contents of a text file into an array of lines. It is intended for relatively small files like config files that are often produced by weird tools (and users).

It automatically handles ASCII, Latin-1 and UTF-8 text. When the file has a BOM, it handles UTF-8, UTF-16 LE and BE, and UTF-32 LE and BE.

Recognized line terminators are NL (Unix, Linux), CRLF (DOS, Windows) and CR (Mac)

    my @lines = loadlines("mydata.txt");
    my @lines = loadlines("mydata.txt", $options);

Basically, the file is opened, read, decoded and split into lines that are returned in the result array. Line terminators are removed.

In scalar context, returns an array reference.

The first argument may be the name of a file, an opened file handle, or a reference to a string that contains the data.

The second argument can be used to influence the behaviour. It is a hash reference of option settings.

Note that loadlines() is a slurper, it reads the whole file into memory and requires temporarily memory for twice the size of the file.

split
Enabled by default.

If set to zero, the data is not split into lines but returned as a single string.

chomp
Enabled by default.

If set to zero, the line terminators are not removed from the resultant lines.

encoding
If specified, loadlines() will use this encoding to decode the file data if it cannot automatically detect the encoding.

If you pass an options hash, File::LoadLines will set "encoding" to the encoding it detected and used for this file data.

There are currently no other modules that handle BOM detection and line splitting.

I have a faint hope that future versions of Perl and Raku will deal with this transparently, but I fear the worst.

When you have raw file data (e.g. from a zip), you can use loadlines() to decode and unpack:

    open( my $data, '<', \$contents );
    $lines = loadlines( $data, $options );

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

Development of this module takes place on GitHub: https://github.com/sciurius/perl-File-LoadLines.

You can find documentation for this module with the perldoc command.

    perldoc File::LoadLines

Please report any bugs or feature requests using the issue tracker on GitHub.

Copyright 2018,2020 Johan Vromans, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2021-08-16 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.