| 1 | package App::nauniq; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 30 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 7 | 30 | our $DATE = '2025-09-24'; # DATE | |||||||||||||||||||||||||||
| 8 | 30 | our $DIST = 'App-nauniq'; # DIST | |||||||||||||||||||||||||||
| 9 | 30 | our $VERSION = '0.112'; # VERSION | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 28 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=23 SCAR=31.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 28 | my %opts = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 28 | my $ifh; # input handle | |||||||||||||||||||||||||||
| 15 | 28 | ▶ | if (@ARGV) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 6 | my $fname = shift @ARGV; | |||||||||||||||||||||||||||
| 17 | 6 | ▶ | if ($fname eq '-') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 4 | $ifh = *STDIN; | |||||||||||||||||||||||||||
| 19 | } else { | ||||||||||||||||||||||||||||
| 20 | 2 | ▶ | open $ifh, "<", $fname or die "Can't open input file $fname: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | } else { | ||||||||||||||||||||||||||||
| 23 | 22 | $ifh = *STDIN; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 28 | my $phase = 2; | |||||||||||||||||||||||||||
| 27 | 28 | my $ofh; # output handle | |||||||||||||||||||||||||||
| 28 | 28 | ▶ | if (@ARGV) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 5 | my $fname = shift @ARGV; | |||||||||||||||||||||||||||
| 30 | 5 | ▶ | if ($fname eq '-') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | $ofh = *STDOUT; | |||||||||||||||||||||||||||
| 32 | } else { | ||||||||||||||||||||||||||||
| 33 | open $ofh, | ||||||||||||||||||||||||||||
| 34 | 5 | ▶ | ($opts{read_output} ? "+" : "") . ($opts{append} ? ">>" : ">"), | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 35 | $fname | ||||||||||||||||||||||||||||
| 36 | or die "Can't open output file $fname: $!\n"; | ||||||||||||||||||||||||||||
| 37 | 5 | ▶ | if ($opts{read_output}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 2 | seek $ofh, 0, 0; | |||||||||||||||||||||||||||
| 39 | 2 | $phase = 1; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||
| 43 | 23 | $ofh = *STDOUT; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 28 | my ($line, $memkey); | |||||||||||||||||||||||||||
| 47 | 28 | my %mem; | |||||||||||||||||||||||||||
| 48 | 29 | ▶ | my $sub_reset_mem = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 49 | 29 | ▶ | if ($opts{num_entries} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 2 | require Tie::Cache; | |||||||||||||||||||||||||||
| 51 | 2 | tie %mem, 'Tie::Cache', $opts{num_entries}; | |||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||
| 53 | 27 | %mem = (); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 28 | }; | |||||||||||||||||||||||||||
| 56 | 28 | $sub_reset_mem->(); | |||||||||||||||||||||||||||
| 57 | 28 | ▶ | require Digest::MD5 if $opts{md5}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 30 | ▶ | no warnings; # we want to shut up 'substr outside of string' | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 28 | while (1) { | |||||||||||||||||||||||||||
| 60 | 179 | ▶ | if ($phase == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | # phase 1 is just reading the output file | ||||||||||||||||||||||||||||
| 62 | 8 | $line = <$ofh>; | |||||||||||||||||||||||||||
| 63 | 8 | ▶ | if (!$line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 2 | $phase = 2; | |||||||||||||||||||||||||||
| 65 | 2 | next; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 171 | $line = <$ifh>; | |||||||||||||||||||||||||||
| 69 | 171 | ▶ | if (!$line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 28 | last; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 149 | ▶ | if ($opts{forget_pattern} && $line =~ $opts{forget_pattern}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts{"forget_pattern"} and $line =~ /$opts{"forget_pattern"}/
MC/DC100%2/2
$opts{"forget_pattern"} and $line =~ /$opts{"forget_pattern"}/
$opts{"forget_pattern"}
$line =~ /$opts{"forget_pattern"}/
Truth table100%3/3
A and B
A= $opts{"forget_pattern"}B= $line =~ /$opts{"forget_pattern"}/
| |||||||||||||||||||||||||||||
| 74 | 1 | $sub_reset_mem->(); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | $memkey = $opts{check_chars} > 0 ? | ||||||||||||||||||||||||||||
| 78 | substr($line, $opts{skip_chars}, $opts{check_chars}) : | ||||||||||||||||||||||||||||
| 79 | 149 | ▶ | substr($line, $opts{skip_chars}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 149 | ▶ | $memkey = lc($memkey) if $opts{ignore_case}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 149 | ▶ | $memkey = Digest::MD5::md5($memkey) if $opts{md5}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 149 | ▶ | if ($phase == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 143 | ▶ | if ($mem{$memkey}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 58 | ▶ | print $ofh $line if $opts{show_repeated}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 85 | ▶ | print $ofh $line if $opts{show_unique}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 149 | $mem{$memkey} = 1; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 30 | 1; | |||||||||||||||||||||||||||
| 97 | # ABSTRACT: Non-adjacent uniq | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||