<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#
# CalcNIFTk.pl
#
# Version 1.02 2007.04.23 - 2007.10.24
# (c) 2007 por Javier Pérez Montes - el.maquinas@terra.es
#
##########
# MODULOS
#
use strict;
use Tk;
use Tk::DialogBox;
sub Calcular;
sub Borrar;
#############
# CONSTANTES
#
my $VERSION = "1.02";
my %NIF = (
    0 =&gt; 'T', 1 =&gt; 'R', 2 =&gt; 'W', 3 =&gt; 'A', 4 =&gt; 'G', 5 =&gt; 'M',
    6 =&gt; 'Y', 7 =&gt; 'F', 8 =&gt; 'P', 9 =&gt; 'D', 10 =&gt; 'X', 11 =&gt; 'B',
    12 =&gt; 'N', 13 =&gt; 'J', 14 =&gt; 'Z', 15 =&gt; 'S', 16 =&gt; 'Q', 17 =&gt; 'V',
    18 =&gt; 'H', 19 =&gt; 'L', 20 =&gt; 'C', 21 =&gt; 'K', 22 =&gt; 'E',
    'DIVISOR' =&gt; 23
);
#######
# MAIN
#
my $mw = MainWindow-&gt;new(-width=&gt;700);
$mw-&gt;title("CalcNIFTk ".$VERSION);
$mw-&gt;configure( -width=&gt;100, -height=&gt;150);
$mw-&gt;resizable( 0, 0 ); # not resizable in any direction
# Construyo los campos
my $frame1 = $mw-&gt;Frame()-&gt;pack(-expand =&gt; '1', -fill =&gt; 'both', -side =&gt; 'top');
$frame1-&gt;Label(-text =&gt; "D.N.I.:")-&gt;pack(-side =&gt; 'left', -padx =&gt; '4');
my $DNI = $frame1-&gt;Entry(-width =&gt; '15', -relief =&gt; 'sunken')-&gt;pack(-side =&gt; 'left', -expand =&gt; '0', -fill =&gt; 'x', -padx =&gt; '4', -pady =&gt; '10');
$frame1-&gt;Label(-text =&gt; "-")-&gt;pack(-side =&gt; 'left');
my $LetraNIF = $frame1-&gt;Entry(-width =&gt; '2', -relief =&gt; 'sunken', -state =&gt; 'normal')-&gt;pack(-side =&gt; 'left', -expand =&gt; '0', -fill =&gt; 'x', -padx =&gt; '4');
#
my $frame2 = $mw-&gt;Frame()-&gt;pack(-expand =&gt; '1', -fill =&gt; 'both', -side =&gt; 'bottom', -padx =&gt; '4', -pady =&gt; '10');
$frame2-&gt;Button(-text =&gt; "Calcular", -underline =&gt; '0', -command =&gt; sub { Calcular; })-&gt;pack(-side =&gt; "left");
$frame2-&gt;Button(-text =&gt; "Borrar", -underline =&gt; '0', -command =&gt; sub { Borrar; })-&gt;pack(-side =&gt; "left", -padx =&gt; '4');
$frame2-&gt;Button(-text =&gt; "Salir", -underline =&gt; '0', -command =&gt; sub { exit; })-&gt;pack(-side =&gt; "right");
# Remapeado de teclas.
$mw-&gt;bind('&lt;KeyPress-C&gt;' =&gt; sub { 
        $DNI -&gt; delete(length($DNI -&gt; get)-1);
        Calcular; 
    });
$mw-&gt;bind('&lt;KeyPress-c&gt;' =&gt; sub { 
        $DNI -&gt; delete(length($DNI -&gt; get)-1);
        Calcular; 
    });
$mw-&gt;bind('&lt;KeyPress-Return&gt;' =&gt; sub { Calcular; });
$mw-&gt;bind('&lt;KeyPress-B&gt;' =&gt; sub { Borrar; });
$mw-&gt;bind('&lt;KeyPress-b&gt;' =&gt; sub { Borrar; });
$mw-&gt;bind('&lt;KeyPress-Escape&gt;' =&gt; sub { exit; });
$mw-&gt;bind('&lt;KeyPress-S&gt;' =&gt; sub { exit; });
$mw-&gt;bind('&lt;KeyPress-s&gt;' =&gt; sub { exit; });
#
$DNI-&gt;focus;
MainLoop;
exit(0);

############
# FUNCIONES
#

# Calcular
sub Calcular {
    my $dni = $DNI -&gt; get;
    if ($dni =~ /^\d+$/) {
        $LetraNIF -&gt; delete(0,length($LetraNIF -&gt; get)) if (length($LetraNIF -&gt; get) &gt; 0);
        $LetraNIF -&gt; insert(0,$NIF{$dni%$NIF{'DIVISOR'}});
    } else {
        warn "El valor introducido no es numérico: '$dni'\n";
        my $dialog = $mw-&gt;DialogBox( -title   =&gt; "Advertencia", -buttons =&gt; [ "Aceptar" ]);
        $dialog-&gt;add("Label", -text =&gt; "El valor introducido no es numérico o está vacío: '$dni'")-&gt;pack;
        $dialog-&gt;Show;
    }
}

# Borrar
sub Borrar {
    $LetraNIF -&gt; delete(0,length($LetraNIF -&gt; get)) if (length($LetraNIF -&gt; get) &gt; 0);
    $DNI -&gt; delete(0,length($DNI -&gt; get)) if (length($DNI -&gt; get) &gt; 0);
}
#FIN
=head1 NAME

CalcNIFTk

=head1 DESCRIPTION

Sample script that calculates the spanish N.I.F. letter.
Script de ejemplo que calcula la letra del N.I.F. 

=head1 README

CalcNIFTk is sample Perl/Tk script that enables you to 
calculate the Spanish NIF letter from NIF number. 
Works under Linux and Windows.

Sorry English users this software was written in Spanish.
Feel free to contact the author for more information.


CalcNIFTk es una script Perl/Tk de ejemplo que le 
permitirá calcular la letra del número NIF utilizado en
España. Funciona bajo Linux y Windows.

=head1 PREREQUISITES

This script requires the C&lt;strict&gt; module.  It also requires C&lt;Tk&gt; and C&lt;Tk::DialogBox&gt;.
Este módulo requiere del módulo C&lt;strict&gt;. Tambien requiere de los módulos C&lt;Tk&gt; y C&lt;Tk::DialogBox&gt;.

=head1 COREQUISITES

=pod OSNAMES

linux
MSWin32

=pod SCRIPT CATEGORIES

Educational
Win32/Utilities

=head1 AUTHOR

CalNIFTk.pl - Copyright 2007 Javier Pérez Montes,  All rights reserved.

This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Este script es software libre, puede redistribuirlo y/o modificarlo bajo los mismo términos que Perl.

=cut

</pre></body></html>