Algori...M10_004(3pm)

๐Ÿ“ฆ
version 1.3.6 ยท 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– CheckDigits::M10_004 โ€” the manual, but make it cute โœจ

okay so bestie, welcome to Algori...M10_004 โ€” yep that's the truncated header, it's section 3pm (User Contributed Perl Documentation), and it lives in the Algorithm::CheckDigits family. She computes check digits! For 2aus5, EAN, ILN, ISBN13, and NVE. Multiple gigs, one module, we love a versatile queen ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

the whole vibe in one go:

use Algorithm::CheckDigits;

$ean = CheckDigits('ean');

if ($ean->is_valid('7622200004607')) {
      # do something
}

$cn = $ean->complete('762220000460');
# $cn = '7622200004607'

$cd = $ean->checkdigit('7622200004607');
# $cd = '7'

$bn = $ean->basenumber('7622200004607');
# $bn = '762220000460'

likeโ€ฆ it just works ๐Ÿ’…


๐ŸŒธ DESCRIPTION ๐ŸŒธ

๐Ÿงฎ ALGORITHM

okay pay attention because this is the whole personality of the module:

  1. Beginning right, all numbers are weighted alternatively 1 and 3 (that is, the check digit is weighted 1). so likeโ€ฆ from the right: 1, 3, 1, 3, no cap ๐ŸŽ€
  2. The sum of all products is computed.
  3. The sum of step 3 ist taken modulo 10. (yes bestie, the page literally says "step 3" here โ€” we are not editing the original, we are respecting her ๐Ÿ˜ญ)
  4. The check digit is the difference between 10 and the number from step 3.

To validate: the total of the digits of all numbers inclusive check digit taken modulo 10 must be 0. that's it, that's the vibe check โœ…

๐Ÿ› ๏ธ METHODS

  • is_valid($number) โ€” Returns true only if $number consists solely of digits, spaces and hyphen and the last digit is a valid check digit according to the algorithm given above.

Returns false otherwise,

  • complete($number) โ€” The check digit for $number is computed and concatenated to the end of $number.

Returns the complete number with check digit or '' if $number does not consist solely of digits, spaces and hyphen.

  • basenumber($number) โ€” Returns the basenumber of $number if $number has a valid check digit.

Return '' otherwise.

  • checkdigit($number) โ€” Returns the checkdigit of $number if $number has a valid check digit.

Return '' otherwise.

๐Ÿ“ฆ EXPORT

None by default. she's lowkey private like that ๐Ÿ™ˆ


๐Ÿ’€ BUGS AND LIMITATIONS ๐Ÿ’€

When invoked as "CheckDigits('isbn13')" the module checks whether the first three digits (the country code) are 978 or 979 โ€” the current (as of 2006) EAN country codes for books. If at any time other EAN country codes for ISBN-13 will be specified and the then responsible maintainer ignores this in the code, please send a friendly email. friendly!!! we are being friendly about it, that's the rule ๐Ÿซถ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

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


๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

perl, CheckDigits, www.pruefziffernberechnung.de.


and that's the whole page, bestie โ€” no notes, she ate ๐Ÿ’…

sign-off time: this beautiful thing is perl v5.36.0, dated 2022-10-13, and it's the Algori...M10_004(3pm) page ๐ŸŽ€ stay valid, stay checkdigited, mwah ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from