Algori...M10_002(3pm)

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

πŸ’– CheckDigits::M10_002 β€” the Algorithm::CheckDigits family's CINS / SIREN / SIRET girlie ✨

okay so bestie, this is the manual page for Algori...M10_002(3pm) β€” that's the User Contributed Perl Documentation one, from the Algorithm::CheckDigits crew. She's a check-digit calculator. Specifically she does CINS (that's the US one), SIREN and SIRET (those two are French πŸ‡«πŸ‡·). Numbers girl math, but make it correct. πŸ’…


🌸 NAME 🌸

CheckDigits::M10_002 β€” she computes check digits for CINS (US), SIREN (FR) and SIRET (FR). No cap.


πŸ¦‹ SYNOPSIS πŸ¦‹

the whole vibe, verbatim, because I would never mess with your code:

  use Algorithm::CheckDigits;

  $siret = CheckDigits('siret');

  if ($siret->is_valid('73282932000074')) {
        # do something
  }

  $cn = $siret->complete('7328293200007');
  # $cn = '73282932000074'

  $cd = $siret->checkdigit('73282932000074');
  # $cd = '4'

  $bn = $siret->basenumber('73282932000074');
  # $bn = '7328293200007'

like, pull in Algorithm::CheckDigits, grab yourself a siret object, and she just… does the rest. main character energy fr fr. 🌈


✨ DESCRIPTION ✨

πŸŽ€ ALGORITHM πŸŽ€

here's the recipe, step by step, and I'm keeping it exactly how she wrote it:

  1. Beginning right all numbers are weighted alternatively 1 and 2.
  2. The total of the digits of all products is computed.
  3. The sum of step 3 ist taken modulo 10.
  4. The check digit is the difference between 10 and the number from step 3 taken modulo 10.
not me noticing she says "ist" in step 3 πŸ‘€ that's the original wording, I'm just the messenger, I promise.

the way that works out: you go from the right side of the number, alternating weights of 1 and 2 πŸͺ„, then you add up all the digits of the products (yes, digits of the products, not the products themselves β€” this is the part everyone gets wrong, iykyk), mod 10 it, and the check digit is whatever gets you from that up to 10, mod 10 again. periodt. πŸ’–

πŸ’… METHODS πŸ’…

is_valid($number)

returns true only if $number is made up of just numbers and the last digit is a valid check digit according to the algorithm up there. ☝️

returns false otherwise.

complete($number)

the check digit for $number gets computed and concatenated onto the end of $number.

returns the complete number with its check digit β€” or '' (empty string, sad) if $number doesn't consist solely of digits and spaces. 🫢

basenumber($number)

gives you back the basenumber of $number, but only if $number has a valid check digit.

returns '' otherwise. πŸ™ˆ

checkdigit($number)

gives you back the checkdigit of $number, again only if $number has a valid check digit.

returns '' otherwise. ⭐

🌟 EXPORT 🌟

None by default. (she's lowkey, she doesn't just dump stuff into your namespace uninvited πŸ’€)


πŸ‘‘ AUTHOR πŸ‘‘

Mathias Weidner, "<mamawe@cpan.org>" β€” iconic, we stan. πŸŽ€


πŸ”₯ SEE ALSO πŸ”₯

  • perl β€” hi mom
  • CheckDigits
  • www.pruefziffernberechnung.de. β€” note the trailing dot, that's exactly how she wrote it, do not @ me
  • www.dsi.cnrs.fr/bureau_qualite/admindonnees/documents/siren.pdf

that's the whole page bestie, go forth and validate your SIRETs πŸ¦‹βœ¨

cute sign-off time: this was perl v5.36.0, dated 2022-10-13, and the page itself is Algori...M10_002(3pm). drink water, check your digits, mwah πŸ’œ
πŸ“¦ where this page comes from