Algori...ase_003(3pm)

πŸ“¦
version 1.3.6 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– CheckDigits::MBase_003 πŸ’–

okay so this page is Algori...ase_003(3pm) from the User Contributed Perl Documentation corner of the world, and it's all about computing check digits for SICI β€” that's a Serial Item and Contribution Identifier, bestie. yes, the same SICI you keep seeing in serials land. let's get into it πŸ’…


🌸 NAME 🌸

CheckDigits::MBase_003 β€” compute check digits for SICI (Serial Item and Contribution Identifier). that's it, that's the whole assignment, and it ate. ✨


✨ SYNOPSIS ✨

the vibe in code form, literally copy-paste it:

use Algorithm::CheckDigits;

$sici = CheckDigits('sici');

if ($sici->is_valid('0784-8679(20040308)6:<138>2.0.TX;2-H')) {
      # do something
}

$cn = $sici->complete('0784-8679(20040308)6:<138>2.0.TX;2-');
# $cn = '0784-8679(20040308)6:<138>2.0.TX;2-H'

$cd = $sici->checkdigit('0784-8679(20040308)6:<138>2.0.TX;2-H');
# $cd = 'H'

$bn = $sici->basenumber('0784-8679(20040308)6:<138>2.0.TX;2-H');
# $bn = '0784-8679(20040308)6:<138>2.0.TX;2-';

see how the check letter just appears? iconic behavior honestly πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

🧚 ALGORITHM 🧚

okay bestie, this is the math part, and no cap it's not scary, it's just seven little steps. watch:

  1. In the string describing the number, all letters (A-Z) get replaced with numbers 10-35 accordingly. and all the other non-numbers? they get replaced by 36. every single one. πŸ’€
  2. Beginning right, the numbers at all odd positions are added. (yes, starting from the right. read it again if you need to, i'll wait 🫢)
  3. The sum from step 1 is multiplied by 3.
  4. Beginning right, the numbers at all even positions are added.
  5. The sums from step 2 and step 3 are added together.
  6. The sum from step 4 is taken modulo 37.
  7. The checksum is 37 minus the sum from step 5 β€” where numbers from 10 to 35 are represented by 'A' to 'Z' accordingly, and 36 is represented by '#'.

periodt. that's the whole algorithm πŸ’…

🌈 METHODS 🌈

  • is_valid($number) β€” Returns true only if the last letter is a valid check letter according to the algorithm given above.

Returns false otherwise. (note the comma in the original, we keep it, we respect it πŸŽ€)

  • complete($number) β€” The check letter for $number is computed and appended the end of $number.

Returns the complete number with check letter, or ''. yeah, empty string if it's not happening. 😭

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

Return '' otherwise. (yes, the original says "Return", not "Returns", and we're keeping that exact energy ✨)

  • checkdigit($number) β€” Returns the check letter of $number if $number has valid check digits.

Return '' otherwise.

πŸ“ EXPORT πŸ“

None by default. nothing jumps into your namespace uninvited, and honestly? boundaries. πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Mathias Weidner, "<mamawe@cpan.org>" β€” absolute legend, authoring banger CPAN modules fr fr πŸ’œ


🌟 SEE ALSO 🌟


and that's the whole page, bestie! 🫢 this lil doc is living in perl v5.36.0, dated 2022-10-13, filed under Algori...ase_003(3pm). go check some SICI digits, you've got this πŸ’…βœ¨

πŸ“¦ where this page comes from