質問

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