• Publicidad

Error "Modification of a read-only value..."

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Error "Modification of a read-only value..."

Notapor coltx » 2012-10-23 13:44 @614

Estimados ayuda, tengo un script el cual lee desde un webservice e inserta en una base de datos en MySQL. Después de un tiempo determinado de correr correctamente me arroja lo siguiente:

Modification of a read-only value attempted at CapturaDatos.pl

¿Qué significa el error?

Gracias.
coltx
Perlero nuevo
Perlero nuevo
 
Mensajes: 79
Registrado: 2011-09-16 08:01 @376

Publicidad

Re: Error "Modification of a read-only value..."

Notapor explorer » 2012-10-23 13:50 @618

Humm... sospecho que estás intentando asignar un valor a una constante. O que has pasado una constante a una subrutina y estás intentando dentro de ella modificar ese valor.

Pon

use diagnostics;

al principio del programa para que Perl te dé más pistas.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Error "Modification of a read-only value..."

Notapor coltx » 2012-10-24 20:52 @911

explorer, al colocar use diagnostics me arroja esto :


Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
Invalid conversion in sprintf: "%A" at Captura.pl line 396 (#2)
    (W printf) Perl does not understand the given format conversion.  See
    perlfunc/sprintf.
   
Invalid conversion in sprintf: "%P" at Captura.pl line 396 (#2)
Invalid conversion in sprintf: "%I" at Captura.pl line 396 (#2)
Invalid conversion in sprintf: "%a" at Captura.pl line 396 (#2)

Modification of a read-only value attempted at Captura.pl line 396 (#3)
    (F) You tried, directly or indirectly, to change the value of a
    constant.  You didn't, of course, try "2 = 1", because the compiler
    catches that.  But an easy way to do the same thing is:
   
        sub mod { $_[0] = 1 }
        mod(2);
   
    Another way is to assign to a substr() that's off the end of the string.
   
    Yet another way is to assign to a foreach loop VAR when VAR
    is aliased to a constant in the look LIST:
   
            $x = 1;
            foreach my $n ($x, 2) {
                $n *= 2; # modifies the $x, but fails on attempt to modify the 2
            }
   
Uncaught exception from user code:
        Modification of a read-only value attempted at Captura.pl line 396.
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
coltx
Perlero nuevo
Perlero nuevo
 
Mensajes: 79
Registrado: 2011-09-16 08:01 @376

Re: Error "Modification of a read-only value..."

Notapor explorer » 2012-10-25 12:10 @548

El mensaje dice que en un printf estás usando un "%A" como formato, y claro, Perl sabe que eso no corresponde a un formato reconocido, y salta el error.

¿Por qué no publicas la línea en cuestión?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 66 invitados

cron