blib/lib/Acme/CPANModules/PickingRandomLinesFromFile.pm

filter: Statementstmt 100% 4 / 4 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 4 / 4 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary
1 package Acme::CPANModules::PickingRandomLinesFromFile;
2  
3 1 our $DATE = '2019-11-27'; # DATE
4 1 our $VERSION = '0.003'; # VERSION
5  
6 1 our $LIST = {
7 summary => 'Picking random lines from a file',
8 tags => ['task'],
9 entries => [
10 {
11 module=>'File::Random',
12 description => <<'_',
13  
14 The `random_line()` function from this module picks one or more random lines
15 from a specified file. The whole content of the file does not need to be slurped
16 into memory, but the routine requires a single-pass of reading all lines from
17 the file. The algorithm is as described in perlfaq (See: `perldoc -q "random
18 line"`).
19  
20 If you pick more than one lines, then there might be duplicates.
21  
22 _
23 },
24 {
25 module=>'File::RandomLine',
26 summary => 'Recommended for large files',
27 description => <<'_',
28  
29 This module gives you a choice of two algorithms. The first is similar to
30 <pm:File::Random> (the scan method), giving each line of the file equal weight.
31 The second algorithm is more interesting: it works by random seeking the file,
32 discarding the line fragment (a.k.a. searching forward for the next newline
33 character), reading the next line, then repeating the process until the desired
34 number of lines is reached. This means one doesn't have to read the whole file
35 and the picking process is much faster than the scan method. It might be
36 preferred for very large files.
37  
38 Note that due to the nature of the algorithm, lines are weighted by the number
39 of characters. In other words, lines that have long lines immediately preceding
40 them will have a greater probability of being picked. Depending on your use case
41 or the line length variation of your file, this algorithm might or might not be
42 acceptable to you.
43  
44 _
45 },
46 {
47 module => 'File::Random::Pick',
48 description => <<'_',
49  
50 This module is an alternative to <pm:File::Random>. It offers a `random_line()`
51 routine that avoids duplication.
52  
53 _
54 },
55 {
56 module => 'App::PickRandomLines',
57 description => <<'_',
58  
59 A CLI that allows you to use <pm:File::Random::Pick> or <pm:File::RandomLine> on
60 the command-line.
61  
62 _
63 },
64 ],
65 };
66  
67 1 1;
68 # ABSTRACT: Picking random lines from a file
69  
70 __END__
↑ Summary