1Algorithm::CheckDigits:U:sMeBrasCeo_n0t0r1i(b3u)ted PerlAlDgoocruimtehnmt:a:tCihoenckDigits::MBase_001(3)
2
3
4

NAME

6       CheckDigits::MBase_001 - compute check digits for UPC (US)
7

SYNOPSIS

9         use Algorithm::CheckDigits;
10
11         $rv = CheckDigits('upc');
12
13         if ($rv->is_valid('012345678905')) {
14               # do something
15         }
16
17         $cn = $rv->complete('01234567890');
18         # $cn = '012345678905'
19
20         $cd = $rv->checkdigit('012345678905');
21         # $cd = '5'
22
23         $bn = $rv->basenumber('012345678905');
24         # $bn = '01234567890'
25

DESCRIPTION

27   ALGORITHM
28       1.  Add all digits in odd-numbered positions.
29
30       2.  Multiply the sum from step 1 with 3.
31
32       3.  Add all digits in even-numbered positions.
33
34       4.  Add the product from step 2 and the sum from step 3.
35
36       5.  If the sum from step 4 is 0 modulo 10, the check digit is 0. Else
37           the check digit is 10 minus the sum from step 4 taken modulo 10.
38
39   METHODS
40       is_valid($number)
41           Returns true only if $number consists solely of numbers and the
42           last digit is a valid check digit according to the algorithm given
43           above.
44
45           Returns false otherwise,
46
47       complete($number)
48           The check digit for $number is computed and concatenated to the end
49           of $number.
50
51           Returns the complete number with check digit or '' if $number does
52           not consist solely of digits and spaces.
53
54       basenumber($number)
55           Returns the basenumber of $number if $number has a valid check
56           digit.
57
58           Return '' otherwise.
59
60       checkdigit($number)
61           Returns the checkdigit of $number if $number has a valid check
62           digit.
63
64           Return '' otherwise.
65
66   EXPORT
67       None by default.
68

AUTHOR

70       Mathias Weidner, "<mamawe@cpan.org>"
71

THANKS

73       Aaron W. West pointed me to a fault in the computing of the check
74       digit.
75

SEE ALSO

77       perl, CheckDigits, www.pruefziffernberechnung.de,
78       www.export911.com/e911/coding/upcChar.htm,
79       www.adams1.com/pub/russadam/upccode.html, http://www.upcdatabase.com.
80
81
82
83perl v5.32.1                      2021-01-2A6lgorithm::CheckDigits::MBase_001(3)
Impressum