Frage

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!

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top