| 1 | package Text::CSV::Separator; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.20'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 4 | our @EXPORT_OK = qw(get_separator); | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 18 | ▶ | sub get_separator { | ||||||||||||||||||||||||||||||
|
Subroutine
get_separator: called CC=51 SCAR=43.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 18 | my %options = @_; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 18 | my $file_path = $options{path}; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | # check options | ||||||||||||||||||||||||||||||||
| 22 | 18 | my $echo; | |||||||||||||||||||||||||||||||
| 23 | 18 | ▶ | if ($options{echo}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 0 | $echo = 1; | |||||||||||||||||||||||||||||||
| 25 | 0 | print "\nDetecting field separator of $file_path\n"; | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 18 | my (@excluded, @included); | |||||||||||||||||||||||||||||||
| 29 | 18 | ▶ | if (exists $options{exclude}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | 6 | @excluded = @{$options{exclude}}; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 18 | ▶ | if (exists $options{include}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | 2 | @included = @{$options{include}}; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 18 | my ($lucky, $colon_timecol, $comma_decsep, $comma_groupsep); | |||||||||||||||||||||||||||||||
| 38 | 18 | ▶ | if (exists $options{lucky} && $options{lucky} == 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options{"lucky"} and $options{"lucky"} == 1
MC/DC50%1/2
exists $options{"lucky"} and $options{"lucky"} == 1
exists $options{"lucky"}
$options{"lucky"} == 1
Truth table66%2/3
A and B
A= exists $options{"lucky"}B= $options{"lucky"} == 1
| |||||||||||||||||||||||||||||||||
| 39 | 9 | $lucky = 1; | |||||||||||||||||||||||||||||||
| 40 | 9 | ▶ | print "Scalar context...\n\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||||
| 42 | 9 | $colon_timecol = $comma_decsep = $comma_groupsep = 1; | |||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | print "List context...\n\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | # options checked | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | # Default set of candidates | ||||||||||||||||||||||||||||||||
| 49 | 18 | my @candidates = (',', ';', ':', '|', "\t"); | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 18 | my %survivors; | |||||||||||||||||||||||||||||||
| 52 | 18 | $survivors{$_} = [] foreach (@candidates); | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 18 | ▶ | if (@excluded > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 6 | foreach (@excluded) { | |||||||||||||||||||||||||||||||
| 56 | 12 | delete $survivors{$_}; | |||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | _message('deleted', $_) if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 18 | ▶ | if (@included > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 2 | foreach (@included) { | |||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | if (length($_) == 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 2 | $survivors{$_} = []; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | _message('added', $_) if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 18 | ▶ | if (keys %survivors == 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 0 | carp "No candidates left!"; | |||||||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 18 | my $csv; | |||||||||||||||||||||||||||||||
| 76 | 18 | ▶ | open ($csv, "<:crlf", $file_path) || croak "Couldn't open $file_path: $!"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 18 | my $record_count = 0; # if $echo | |||||||||||||||||||||||||||||||
| 79 | 18 | ▶ | while (<$csv>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 5134 | my $record = $_; | |||||||||||||||||||||||||||||||
| 81 | 5134 | chomp $record; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 5134 | ▶ | if ($echo) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | $record_count++; | |||||||||||||||||||||||||||||||
| 85 | 0 | print "\nRecord #$record_count\n"; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 5134 | foreach my $candidate (keys %survivors) { | |||||||||||||||||||||||||||||||
| 89 | 10314 | ▶ | _message('candidate', $candidate) if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 10314 | my $rex = qr/\Q$candidate\E/; | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 10314 | my $count = 0; | |||||||||||||||||||||||||||||||
| 94 | 10314 | ▶ | $count++ while ($record =~ /$rex/g); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 10314 | ▶ | print "Count: $count\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 10314 | ▶ | if ($count > 0 && !$lucky) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$count > 0 and not $lucky
MC/DC100%2/2
$count > 0 and not $lucky
$count > 0
not $lucky
Truth table100%3/3
A and not(B)
A= $count > 0B= not $lucky
| |||||||||||||||||||||||||||||||||
| 99 | 5130 | push @{$survivors{$candidate}}, $count; | |||||||||||||||||||||||||||||||
| 100 | } elsif ($count == 0) { | ||||||||||||||||||||||||||||||||
| 101 | 54 | delete $survivors{$candidate}; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 5134 | ▶ | if (!$lucky) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 2567 | ▶ | $colon_timecol = _regularity($record, 'timecol') if $colon_timecol; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | 2567 | ▶ | $comma_decsep = _regularity($record, 'decsep') if $comma_decsep; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | 2567 | ▶ | $comma_groupsep = _regularity($record, 'groupsep') if $comma_groupsep; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 5134 | my @alive = keys %survivors; | |||||||||||||||||||||||||||||||
| 114 | 5134 | my $survivors_count = @alive; | |||||||||||||||||||||||||||||||
| 115 | 5134 | ▶ | if ($survivors_count == 1) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | if ($echo) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 0 | _message('detected', $alive[0]); | |||||||||||||||||||||||||||||||
| 118 | 0 | print "Returning control to caller...\n\n"; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | 8 | close $csv; | |||||||||||||||||||||||||||||||
| 121 | 8 | ▶ | if (!$lucky) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | 4 | return @alive; | |||||||||||||||||||||||||||||||
| 123 | } else { | ||||||||||||||||||||||||||||||||
| 124 | 4 | return $alive[0]; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | } elsif ($survivors_count == 0) { | ||||||||||||||||||||||||||||||||
| 127 | 2 | carp "\nNo candidates left!\n"; | |||||||||||||||||||||||||||||||
| 128 | 2 | return; | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | # More than 1 survivor. 2nd pass to determine count variability | ||||||||||||||||||||||||||||||||
| 133 | 8 | ▶ | if ($lucky) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | print "\nSeveral candidates left\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | 4 | carp "\nBad luck. Couldn't determine the separator of $file_path.\n"; | |||||||||||||||||||||||||||||||
| 136 | 4 | return; | |||||||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | print "\nVariability:\n\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 139 | 4 | my %std_dev; | |||||||||||||||||||||||||||||||
| 140 | 4 | foreach my $candidate (keys %survivors) { | |||||||||||||||||||||||||||||||
| 141 | 9 | my $mean = _mean(@{$survivors{$candidate}}); | |||||||||||||||||||||||||||||||
| 142 | 9 | $std_dev{$candidate} = _std_dev($mean, @{$survivors{$candidate}}); | |||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | if ($echo) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | 0 | _message('candidate', $candidate); | |||||||||||||||||||||||||||||||
| 145 | 0 | print "Mean: $mean\tStd Dev: $std_dev{$candidate}\n\n"; | |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | print "Couldn't determine the separator\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 4 | close $csv; | |||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 4 | my @penalized; | |||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | if ($colon_timecol) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | print "Detected time column\n" if $echo; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | 1 | delete $survivors{':'}; | |||||||||||||||||||||||||||||||
| 157 | 1 | push @penalized, ':'; | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | if ($comma_decsep || $comma_groupsep) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$comma_decsep or $comma_groupsep
MC/DC50%1/2
$comma_decsep or $comma_groupsep
$comma_decsep
$comma_groupsep
Truth table66%2/3
A or B
A= $comma_decsepB= $comma_groupsep
| |||||||||||||||||||||||||||||||||
| 161 | 1 | delete $survivors{','}; | |||||||||||||||||||||||||||||||
| 162 | 1 | push @penalized, ','; | |||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | if ($echo && $comma_decsep) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$echo and $comma_decsep
MC/DC0%0/2
$echo and $comma_decsep
$echo
$comma_decsep
Truth table33%1/3
A and B
A= $echoB= $comma_decsep
| |||||||||||||||||||||||||||||||||
| 164 | 0 | print "\nDetected comma-separated decimal numbers column\n"; | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | if ($echo && $comma_groupsep) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$echo and $comma_groupsep
MC/DC0%0/2
$echo and $comma_groupsep
$echo
$comma_groupsep
Truth table33%1/3
A and B
A= $echoB= $comma_groupsep
| |||||||||||||||||||||||||||||||||
| 167 | 0 | print "\nDetected comma-grouped numbers column\n"; | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 4 | my @alive = sort {$std_dev{$a} <=> $std_dev{$b}} keys %survivors; | |||||||||||||||||||||||||||||||
| 172 | 0 | push @alive, sort {$std_dev{$a} <=> $std_dev{$b}} @penalized; | |||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | if ($echo) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | 0 | print "Remaining candidates: "; | |||||||||||||||||||||||||||||||
| 175 | 0 | foreach my $left (@alive) { | |||||||||||||||||||||||||||||||
| 176 | 0 | _message('left', $left); | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | 0 | print "\n\nReturning control to caller...\n\n"; | |||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | 4 | return @alive; | |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | 9 | ▶ | sub _mean { | ||||||||||||||||||||||||||||||
|
Subroutine
_mean: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 185 | 9 | my @array = @_; | |||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 9 | my $sum = 0; | |||||||||||||||||||||||||||||||
| 188 | 9 | $sum += $_ foreach (@array); | |||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 9 | my $mean = $sum / scalar(@array); | |||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 9 | return $mean; | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 9 | ▶ | sub _std_dev { | ||||||||||||||||||||||||||||||
|
Subroutine
_std_dev: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 196 | 9 | my ($mean, @array) = @_; | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 9 | my $sum = 0; | |||||||||||||||||||||||||||||||
| 199 | 9 | $sum += ($_ - $mean)**2 foreach (@array); | |||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | 9 | my $std_dev = sqrt( $sum / scalar(@array) ); | |||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 9 | return $std_dev; | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 2579 | ▶ | sub _regularity { | ||||||||||||||||||||||||||||||
|
Subroutine
_regularity: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 207 | 2579 | my ($string, $kind) = @_; | |||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | 2579 | my $time_rx = qr/ | |||||||||||||||||||||||||||||||
| 210 | (?:^|(?<=\s|[T,;|\t])) | ||||||||||||||||||||||||||||||||
| 211 | (?:[01]?[0-9]|2[0-3]) # hours | ||||||||||||||||||||||||||||||||
| 212 | : | ||||||||||||||||||||||||||||||||
| 213 | (?:[0-5][0-9]) # minutes | ||||||||||||||||||||||||||||||||
| 214 | (?::[0-5][0-9])? # seconds | ||||||||||||||||||||||||||||||||
| 215 | (?: | ||||||||||||||||||||||||||||||||
| 216 | Z | ||||||||||||||||||||||||||||||||
| 217 | | | ||||||||||||||||||||||||||||||||
| 218 | \.\d+ | ||||||||||||||||||||||||||||||||
| 219 | | | ||||||||||||||||||||||||||||||||
| 220 | (?:\+|-) | ||||||||||||||||||||||||||||||||
| 221 | (?:[01]?[0-9]|2[0-3]) | ||||||||||||||||||||||||||||||||
| 222 | : | ||||||||||||||||||||||||||||||||
| 223 | (?:[0-5][0-9]) | ||||||||||||||||||||||||||||||||
| 224 | )? | ||||||||||||||||||||||||||||||||
| 225 | (?=$|\s|[,;|\t]) | ||||||||||||||||||||||||||||||||
| 226 | /x; | ||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 2579 | my $commadecsep_rx = qr/ | |||||||||||||||||||||||||||||||
| 229 | (?:^|(?<=[^\d,.])) | ||||||||||||||||||||||||||||||||
| 230 | (?: | ||||||||||||||||||||||||||||||||
| 231 | [-+]? | ||||||||||||||||||||||||||||||||
| 232 | (?: | ||||||||||||||||||||||||||||||||
| 233 | \d{0,3}?(?:\.\d{3})* | ||||||||||||||||||||||||||||||||
| 234 | | | ||||||||||||||||||||||||||||||||
| 235 | \d+ | ||||||||||||||||||||||||||||||||
| 236 | ) | ||||||||||||||||||||||||||||||||
| 237 | ,\d+ | ||||||||||||||||||||||||||||||||
| 238 | ) | ||||||||||||||||||||||||||||||||
| 239 | (?=$|[^\d,.]) | ||||||||||||||||||||||||||||||||
| 240 | /x; | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | 2579 | my $commagroupsep_rx = qr/ | |||||||||||||||||||||||||||||||
| 243 | (?:^|(?<=[^\d,.])) | ||||||||||||||||||||||||||||||||
| 244 | (?: | ||||||||||||||||||||||||||||||||
| 245 | [-+]?\d{0,3}? | ||||||||||||||||||||||||||||||||
| 246 | (?:,\d{3})+ | ||||||||||||||||||||||||||||||||
| 247 | (?:\.\d+)? | ||||||||||||||||||||||||||||||||
| 248 | ) | ||||||||||||||||||||||||||||||||
| 249 | (?=$|[^\d,.]) | ||||||||||||||||||||||||||||||||
| 250 | /x; | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | 2579 | ▶ | return 0 if ($kind eq 'timecol' && $string !~ /$time_rx/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind eq "timecol" and not $string =~ /$time_rx/
MC/DC100%2/2
$kind eq "timecol" and not $string =~ /$time_rx/
$kind eq "timecol"
not $string =~ /$time_rx/
Truth table100%3/3
A and not(B)
A= $kind eq "timecol"B= not $string =~ /$time_rx/
| |||||||||||||||||||||||||||||||||
| 254 | 2571 | ▶ | return 0 if ($kind eq 'decsep' && $string !~ /$commadecsep_rx/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind eq "decsep" and not $string =~ /$commadecsep_rx/
MC/DC100%2/2
$kind eq "decsep" and not $string =~ /$commadecsep_rx/
$kind eq "decsep"
not $string =~ /$commadecsep_rx/
Truth table100%3/3
A and not(B)
A= $kind eq "decsep"B= not $string =~ /$commadecsep_rx/
| |||||||||||||||||||||||||||||||||
| 255 | 2563 | ▶ | return 0 if ($kind eq 'groupsep' && $string !~ /$commagroupsep_rx/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$kind eq "groupsep" and not $string =~ /$commagroupsep_rx/
MC/DC50%1/2
$kind eq "groupsep" and not $string =~ /$commagroupsep_rx/
$kind eq "groupsep"
not $string =~ /$commagroupsep_rx/
Truth table66%2/3
A and not(B)
A= $kind eq "groupsep"B= not $string =~ /$commagroupsep_rx/
| |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | 2554 | return 1; | |||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub _message { | ||||||||||||||||||||||||||||||
|
Subroutine
_message: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 261 | 0 | my ($type, $candidate) = @_; | |||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | 0 | my $char; | |||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if (ord $candidate == 9) { # tab character | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 265 | 0 | $char = "\\t"; | |||||||||||||||||||||||||||||||
| 266 | } else { | ||||||||||||||||||||||||||||||||
| 267 | 0 | $char = $candidate; | |||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 0 | my %message = ( | |||||||||||||||||||||||||||||||
| 271 | deleted => "Deleted $char from candidates list\n", | ||||||||||||||||||||||||||||||||
| 272 | added => "Added $char to candidates list\n", | ||||||||||||||||||||||||||||||||
| 273 | candidate => "Candidate: $char\t", | ||||||||||||||||||||||||||||||||
| 274 | detected => "\nSeparator detected: $char\n", | ||||||||||||||||||||||||||||||||
| 275 | left => " $char ", | ||||||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 0 | print $message{$type}; | |||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 4 | 1; | |||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | __END__ | ||||||||||||||||||||||||||||||||