Algori...M11_001(3pm)

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

๐Ÿ’– CheckDigits::M11_001 โ€” okay bestie, let's talk check digits ๐Ÿ’–

So this is CheckDigits::M11_001 (under the User Contributed Perl Documentation umbrella, and the manpage is literally titled Algori...M11_001(3pm) because Unix hates long names, slay). It's the module that computes check digits for ISBN, ISSN, VAT RN (PT), HKID (HK), Wagon number (BR), NHS (GB), and VAT (SL). Seven whole vibes, one algorithm. Periodt. โœจ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

use Algorithm::CheckDigits;

$isbn = CheckDigits('isbn');

if ($isbn->is_valid('3-88229-192-3')) {
      # do something
}

$cn = $isbn->complete('3-88229-192-');
# $cn = '3-88229-192-3'

$cd = $isbn->checkdigit('3-88229-192-3');
# $cd = '3'

$bn = $isbn->basenumber('3-88229-192-3');
# $bn = '3-88229-192-'

That's it, that's the whole entrance. Pull the module in, grab the flavor you want, and let it validate / complete / slice / dice your numbers. ๐Ÿฆ‹


โœจ DESCRIPTION โœจ

๐Ÿงฎ ALGORITHM ๐Ÿงฎ

Not me explaining this like we're doing homework together โ€” but it's actually cute, watch:

  1. The sequence of digits is processed right to left. Every digit is multiplied with their position in the sequence (i.e. the digit left to the check digit has the weight 2 then 3 etc.).

With a Hongkong ID (hkid) the leftmost char is replaced with its position in the alphabet and then multiplied with 8 (its weight).

  1. The sum of all products is computed. โž•
  2. The sum of step 2 is taken modulo 11. ๐Ÿ”
  3. The checkdigit is the difference of the sum from step 3 to eleven, under the following conditions:
    • isbn, issn
      • If the difference is 10, the check digit is 'X'.
      • If the difference is 11, the check digit is 0.
    • ustid_pt
      • If the difference is greater then 9, the check digit is '0'.
    • hkid
      • If the difference is 10, the check digit is 'A'.
      • If the difference is 11, the check digit is 0.
    • wagonnr_br
      • If the difference is 10, the check digit is 0.
      • If the difference is 11, the check digit is 1.
    • nhs_gb
      • If the difference is 10, the number would not be taken.
      • If the difference is 11, the check digit is 0.
    • vat_sl
      • This is a little bit unclear, don't trust on the method for this type. ๐Ÿšฉ
Real talk for a sec: that vat_sl line is a genuine "idk bestie" from the original. The docs literally say this one is a little bit unclear and you shouldn't trust the method for this type. Don't build anything mission-critical on it, mkay? ๐Ÿ™ˆ

๐Ÿซถ METHODS ๐Ÿซถ

  • is_valid($number) โ€” Returns true only if $number consists solely of numbers 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 and spaces.

  • 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. Zero, zilch, nada. You want stuff? Import it yourself, bestie. ๐Ÿ’…


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Mathias Weidner, <mamawe@cpan.org> โ€” absolute icon, wrote the whole thing. ๐ŸŒˆ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

perl, CheckDigits, www.pruefziffernberechnung.de.


Okay that's the whole page, you ate that. No cap. ๐Ÿ“ This little beauty is perl v5.36.0, dated 2022-10-13 โ€” and the manpage header/footer knows it as Algori...M11_001(3pm) from the User Contributed Perl Documentation collection. Go forth and validate those digits, main character. ๐ŸŽ€๐Ÿ’œโœจ

๐Ÿ“ฆ where this page comes from