I have this function that i need in perl:

<?php
function dv($r){$s=1;for($m=0;$r!=0;$r/=10)$s=($s+$r%10*(9-$m++%6))%11;
return chr($s?$s+47:75);}
?>

I've got this from here, where is already a perl function intended to do the same task (here) but it doesn't calculate correctly sometimes. PHP function does work perfectly.

Thanks in advance!

有帮助吗?

解决方案

That PHP can be translated into perl rather directly:

sub dv{
   my $r=pop;
   my ($s, $m) = (1, 0);
   for(;$r!=0;$r/=10) {
      $s=($s+$r%10*(9-$m++%6))%11;
   }
   return chr($s?$s+47:75);
}

Extra newlines because... wow. That's ugly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top