File-LoadLines
view release on metacpan or search on metacpan
lib/File/LoadLines.pm view on Meta::CPAN
By default the function loadlines() is exported.
=head1 FUNCTIONS
=head2 loadlines
@lines = loadlines("mydata.txt");
@lines = loadlines("mydata.txt", $options);
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 name of a file on disk may start with C<"file://">, this is ignored.
If the name starts with C<"http:"> or C<"https:"> the data will be
retrieved using LWP.
L<Data URLs|https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs> like C<"data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="> are
lib/File/LoadLines.pm view on Meta::CPAN
elsif ( $filename eq '-' ) {
$filename = "__STDIN__";
binmode( STDIN, ':raw' );
$data = do { local $/; <STDIN> };
}
elsif ( $filename =~ /^https?:/ ) {
require LWP::UserAgent;
my $ua = LWP::UserAgent->new( timeout => 20 );
my $res = $ua->get($filename);
if ( $res->is_success ) {
$data = $res->decoded_content;
}
elsif ( $options->{fail} eq "soft" ) {
$options->{error} = $res->status_line;
return;
}
else {
croak("$filename: ", $res->status_line);
}
}
elsif ( $filename =~ /^data:/ ) {
( run in 0.459 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )