Validate an ISSN using Perl
Last week I wrote about validating an ISBN, so this week I thought I would post the code to validate an ISSN.
There are only a few minor differences between validating an ISSN and ISBN.
sub valid_issn {
my $issn = $_[0];
$issn =~ s/[^\dX]//gi;
return if length($issn) != 8;
my $sum = 0;
my @chars = split('', $issn);
$chars[7] = 10 if uc($chars[7]) eq 'X';
for (my $char = 0; $char < @chars; $char++) {
$sum += (8-$char) * $chars[$char];
}
return (($sum % 11) == 0);
}