Algori...M11_017(3pm)

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

πŸ’– Algorithm::CheckDigits::M11_017 πŸ’–

okay so bestie, this is Algorithm::CheckDigits::M11_017 β€” the section 3pm one, aka the Perl module that computes check digits for EC-No, EINECS and ELINCS. yes it's a mouthful. yes it's iconic. let's go πŸ¦‹


✨ SYNOPSIS ✨

use Algorithm::CheckDigits;

$ecno = CheckDigits('ecno');

if ($ecno->is_valid('200-236-6')) {
      # do something
}

$cn = $ecno->complete('200-236-');
# $cn = '200-236-6'

$cd = $ecno->checkdigit('200-236-6');
# $cd = '6'

$bn = $ecno->basenumber('200-236-6');
# $bn = '200-236-'

like, look at her go πŸŽ€ that's the whole vibe right there.


πŸ’… DESCRIPTION πŸ’…

🌸 ALGORITHM 🌸

the whole tea, in three little steps:

  1. going from left to right, every single digit gets multiplied by its position in the sequence. like a little lineup. everyone gets a number. no cap.
  2. you add up all those products. sum time. ✨
  3. that sum gets taken modulo 11. and the check digit? it's the last digit of the result. periodt.

🫢 METHODS 🫢

  • is_valid($number) β€” returns true only if $number is made up of nothing but numbers and that last digit is a valid check digit according to the algorithm above. anything else? false. she's picky and honestly? valid. πŸ’…
  • complete($number) β€” computes the check digit for $number and sticks it right onto the end. returns the complete number with the check digit, or '' if $number isn't purely digits and spaces. πŸŽ€
  • basenumber($number) β€” hands you the basenumber of $number if $number has a valid check digit. otherwise it returns ''. πŸ™ˆ
  • checkdigit($number) β€” hands you the checkdigit of $number if $number has a valid check digit. otherwise, you guessed it: ''. πŸ’€

πŸ‘‘ EXPORT πŸ‘‘

None by default. she gives you nothing for free, bestie. boundaβ€” I mean, boundaries. healthy ones. 😌


⭐ AUTHOR ⭐

Mathias Weidner, "<mamawe@cpan.org>" β€” we love a legend who signs their work. 🫢


🌈 SEE ALSO 🌈


ok that's the page!! no missing options, no skipped steps, nothing snuck in that wasn't already there. that's the rule and we respect it. πŸ”₯

and that's a wrap, bestie πŸ’– this whole thing is documented for perl v5.36.0, dated 2022-10-13 β€” so like, she's got a little history and she's still serving. go forth and validate those EC-Nos. slay. πŸ‘‘βœ¨

πŸ“¦ where this page comes from