PERL: Dígito verificador con Perl (Chile).
#!/usr/bin/perl
use strict;
use warnings;
my $s_Rut = "30686957";
my @a_rut = split '', $s_Rut;
print("@a_rut" ."\n");
my @rut_rev = reverse @a_rut;
print("@rut_rev" ."\n");
my $adding=0;
my $multi=2;
foreach my $n (@rut_rev) {
print ("$n \n");
$adding = $adding + ($n * $multi++);
if($multi==8){
$multi=2;
}
}
print ("$adding \n");
my $module=$adding%11;
my $dv=11-$module;
if($dv == 11){
$dv=0;
}
if($dv == 10){
$dv='K';
}
$s_Rut="$s_Rut-$dv";
print("RUT: $s_Rut\n");
Comentarios