in reply to Re: (dkubb) Re: (2) YAL10CI (Yet Another LUHN-10 Checksum Implementation)
in thread YAL10CI (Yet Another LUHN-10 Checksum Implementation)
johannz you are right! I had no idea the range operator (...) was persistent across subroutine calls. I expected it to maintain it's state while inside the while loop, but reset itself each time the subroutine was called.
perlop gives an explanation of the ... operator. It's definately something I have not used much before, or seen used, so I wanted to give it a try.
While I was trying to figure out why my example didn't work in all cases, I came up with the following that returned the correct values during testing:
sub dkubb_LUHN10 { my $number = shift || return 0; my $sum; $sum += chop($number) + $LUHN10_map[chop $number] while "$number"; ($sum % 10 == 0) || 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (dkubb) Re: (4) YAL10CI (Yet Another LUHN-10 Checksum Implementation)
by johannz (Hermit) on Mar 14, 2001 at 01:33 UTC |