File Coverage

blib/lib/Acme/CPANModules/ReadingFilesBackward.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Acme::CPANModules::ReadingFilesBackward;
2              
3 1     1   361243 use strict;
  1         4  
  1         46  
4              
5 1     1   642 use Acme::CPANModulesUtil::Misc;
  1         582  
  1         158  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2023-10-31'; # DATE
9             our $DIST = 'Acme-CPANModules-ReadingFilesBackward'; # DIST
10             our $VERSION = '0.003'; # VERSION
11              
12             our $LIST = {
13             summary => 'List of modules to read files backward (in reverse)',
14             description => <<'_',
15              
16             Probably the fastest way, if you are on a Unix system, is to use the **tac**
17             command, which can read a file line by line in reverse order, or paragraph by
18             paragraph, or character by character, or word by word, or by a custom separator
19             string or regular expression. Example for using it from Perl:
20              
21             open my $fh, "tac /etc/passwd |";
22             print while <$fh>;
23              
24             Another convenient way is to use the Perl I/O layer . It
25             only does line-by-line reversing, but you can use the regular Perl API. You
26             don't even have to `use` the module explicitly (but of course you have to get it
27             installed first):
28              
29             open my $fh, "<:reverse", "/etc/passwd";
30             print while <$fh>;
31              
32             If your file is small (fits in your system's memory), you can also slurp the
33             file contents first into an array (either line by line, or paragraph by
34             paragraph, or what have you) and then simply `reverse` the array:
35              
36             open my $fh, "<", "/etc/passwd";
37             my @lines = <$fh>;
38             print for reverse @lines;
39              
40             If the above solutions do not fit your needs, there are also these modules which
41             can help: , . File::ReadBackward
42             is slightly faster than File::Bidirectional, but File::Bidirectional can read
43             forward as well as backward. I now simply prefer PerlIO::reverse because I don't
44             have to use a custom API for reading files.
45              
46             _
47             'x.app.cpanmodules.show_entries' => 0,
48             };
49              
50             Acme::CPANModulesUtil::Misc::populate_entries_from_module_links_in_description;
51              
52             1;
53             # ABSTRACT: List of modules to read files backward (in reverse)
54              
55             __END__