Algorithm-CheckDigits

 view release on metacpan or  search on metacpan

lib/Algorithm/CheckDigits/MXX_003.pm  view on Meta::CPAN

	for (my $i = 1; $i <= $#digits; $i++) {
		my $pi = $perm->[$i % 8]->[$digits[$i]];
		$rd = $dieder->[$rd]->[$pi];
	}
	for (my $j = 0; $j <= 9; $j++) {
		return $j unless($dieder->[$rd]->[$j]);
	}

	return -1;
} # _compute_checkdigit()

# Preloaded methods go here.

1;
__END__

=encoding iso-8859-1

=head1 NAME

CheckDigits::MXX_003 - compute check digits for DEM

=head1 SYNOPSIS

  use Algorithm::CheckDigits;

  $dem = CheckDigits('dem');

  if ($dem->is_valid('GD0645027K1')) {
	# do something
  }

  $cn = $dem->complete('GD0645027K');
  # $cn = 'GD0645027K1'

  $cd = $dem->checkdigit('GD0645027K1');
  # $cd = '1'

  $bn = $dem->basenumber('GD0645027K1');
  # $bn = 'GD0645027K'
  
=head1 DESCRIPTION

=head2 ALGORITHM

The algorithm is a variation of the Verhoeff scheme.

=over 4

=item S<0>

All letters are changed to numbers.

=item S<1>

All digits are permutated according to a permutation table.

=item S<2>

The permutated digits are combined using a diëder table. The first
with the second, the result with the third, this result with the
fourth and so on.

=item S<3>

The result of the last combination in the diëder table is in such a
way combined that the result is 0 (zero). The number used for this
combination is the checksum.

=back

For details look at the source.

=head2 METHODS

=over 4

=item is_valid($number)

Returns true only if C<$number> consists solely of numbers and the last digit
is a valid check digit according to the algorithm given above.

Returns false otherwise,

=item complete($number)

The check digit for C<$number> is computed and concatenated to the end
of C<$number>.

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

=item basenumber($number)

Returns the basenumber of C<$number> if C<$number> has a valid check
digit.

Return '' otherwise.

=item checkdigit($number)

Returns the checkdigit of C<$number> if C<$number> has a valid check
digit.

Return '' otherwise.

=back

=head2 EXPORT

None by default.

=head1 AUTHOR

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

=head1 THANKS

=head1 SEE ALSO

L<perl>,



( run in 1.056 second using v1.01-cache-2.11-cpan-39bf76dae61 )