UPC: Difference between revisions
m
→{{header|Perl}}: tweaks
m (calculate functions only once) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: tweaks) |
||
Line 313:
sub decode_UPC {
my($line) = @_;
my(%pattern_to_digit_1,%pattern_to_digit_2,@patterns1,@patterns2,@digits,$sum);
push @patterns1, $p;
}
$pattern_to_digit_1{$patterns1[$_]} = $_ for 0..$#patterns1;
Line 331:
my($match1,$match2) = ($+{match1}, $+{match2});
push @digits, $pattern_to_digit_1{$_} for $match1 =~ /(.
push @digits, $pattern_to_digit_2{$_} for $match2 =~ /(.
$sum += (3,1)[$_%2] * $digits[$_] for 0..11;
$sum % 10 ? '' : join '', @digits;
|