• Publicidad

Expresiones Regulares de Perl en CGI

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

Expresiones Regulares de Perl en CGI

Notapor Skull118 » 2014-02-25 18:08 @797

Buenas tardes, nuevamente acudo a Perl en Español, debido a que presento un problema al ejecutar un script del lado del servidor, y no regresa mayor información, ni en el log de Apache, ni mucho menos vía html.


El problema pude verificar, está en la expresión regular, la cual al descomentarla, pasa sin ningún problema hasta el final, dándome el alert de JavaScript que le puse.


Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!C:/Perl64/bin/perl.exe
  2. use CGI;
  3. foreach$a(my @a=glob("*.TXT")){
  4.         if($a=~m/TV/){
  5.                 print("content-type: text/html \n\n");
  6.                 print("<script language='javascript'>alert('LLAMARIA AL SCRIPT DE TV');</script>");
  7.         }
  8. }
  9. exit(1);
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4

En html solo me da este error:
Sintáxis: [ Descargar ] [ Ocultar ]
Using html4strict Syntax Highlighting
  1. Internal Server Error
  2.  
  3. The server encountered an internal error or misconfiguration and was unable to complete your request.
  4.  
  5. Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
  6.  
  7. More information about this error may be available in the server error log.
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

De antemano agradezco la ayuda.
Skull118
Perlero nuevo
Perlero nuevo
 
Mensajes: 53
Registrado: 2013-03-21 13:38 @610

Publicidad

Re: Expresiones Regulares de Perl en CGI

Notapor Skull118 » 2014-02-25 18:11 @799

Compañeros, ya encontré cuál era el problema, en el if (donde está la expresión regular) debo escaparla:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. if($a=\~m/TV/){
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Skull118
Perlero nuevo
Perlero nuevo
 
Mensajes: 53
Registrado: 2013-03-21 13:38 @610

Re: Expresiones Regulares de Perl en CGI

Notapor explorer » 2014-02-25 20:12 @883

Humm... eso no es Perl... Mejor así:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. if ($a =~ m/TV/) {
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
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: Expresiones Regulares de Perl en CGI

Notapor Skull118 » 2014-02-26 11:07 @504

explorer, buenos días (en mi caso). Te comento que con la expresión que me brindaste, mi problema continúa, este es el script que en consola me funciona perfectamente, pero en la web no me regresa la decisión correcta.

Archivos dentro de la carpeta CGI:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
TV20140226.TXT
VG20140226.TXT
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

O me dice en ambos que correrá el script TV (el cuál será otro problema más adelante, estoy casi seguro) o me dice que no sabe qué script debe de correr en ambos archivos.

Una pregunta adicional: ¿en dónde podría empezar a ver la sintaxis básica para poder empezar a generar scripts web en Perl? De antemano muchas gracias por el apoyo, mi más grande respeto y admiración.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!C:/Perl64/bin/perl.exe -w
  2. use strict;
  3. print("content-type: text/html \n\n");
  4. foreach$a(my @a=glob("*.TXT")){
  5.         my $ar=$a;
  6.         my $ar =~ s/\s$*//g;
  7.         my $co="^TV";
  8.         my $l="<script language='javascript'>alert('".$ar."');</script>";      
  9.         if ($a !~ m/$co/) {
  10.                 my $l="<script language='javascript'>alert('LLAMARIA AL SCRIPT DE TV CON EL ARCHIVO ".$ar."');</script>";
  11.                 print($l);
  12.         }
  13.         else{          
  14.                 my $l=("<script language='javascript'>alert('NO SE CUAL PROCEDIMIENTO CORRERIA CON EL ARCHIVO ".$ar."');</script>");
  15.                 print($l);
  16.         }
  17. }
  18. exit(1);
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
Skull118
Perlero nuevo
Perlero nuevo
 
Mensajes: 53
Registrado: 2013-03-21 13:38 @610

Re: Expresiones Regulares de Perl en CGI

Notapor reLlene » 2014-02-26 11:13 @509

Skull118: ¿necesitas escapar algún carácter especial? Porque así como lo tienes no lo consigues, ¡¡como dice explorer arriba!!
Por cierto... el error que obtienes del servidor puede disparar MUCHOS motivos, ¡¡nada mejor que echarle una mirada al error log del mismo!!

EDIT: veo que publicamos al unísono y acabo de ver tu nuevo mensaje :lol:

Te dejo dos tutoriales del foro donde hablan lo básico de expresiones regulares para que vayan ajustando mejor lo que quieres capturar o detectar. Luego puedes mirar más por la red.

http://perlenespanol.com/tutoriales/exp ... bases.html

http://perlenespanol.com/tutoriales/exp ... medio.html

y otro consejo es el que le eches una mirada al scope (y su alcance) de las variables en Perl
Sexo : unzip ; strip ; touch ; grep ; finger ;mount ; fsck ; more ; yes ; umount ; sleep.
Avatar de Usuario
reLlene
Perlero nuevo
Perlero nuevo
 
Mensajes: 97
Registrado: 2012-06-04 07:16 @344

Re: Expresiones Regulares de Perl en CGI

Notapor Skull118 » 2014-02-26 12:04 @544

reLlene: Te comento, en consola, el script funciona excelente, sin embargo cuando intento ejecutarlo desde el servidor, pareciera ser, que no ejecuta la expresión regular, las mismas las he utilizado en reiteradas ocasiones, sin mayores inconvenientes, más que cuando son expresiones sumamente complejas, en las cuales el maestro explorer, le ha echado una mano.
Skull118
Perlero nuevo
Perlero nuevo
 
Mensajes: 53
Registrado: 2013-03-21 13:38 @610

Re: Expresiones Regulares de Perl en CGI

Notapor reLlene » 2014-02-26 13:14 @593

Dices "cuando intento ejecutarlo desde el servidor, pareciera ser, que no ejecuta la expresión regular". ¿Quiere decir que el resto se imprime? ¿U obtienes una vez más error del servidor? ¿Tiene permisos el script para correr en el servidor? Veo que estás en Windows pero quizás la restricción sea otra, por eso ¡¡INSISTO en que revises el log del servidor para dar con el clavo de lleno!!
Sexo : unzip ; strip ; touch ; grep ; finger ;mount ; fsck ; more ; yes ; umount ; sleep.
Avatar de Usuario
reLlene
Perlero nuevo
Perlero nuevo
 
Mensajes: 97
Registrado: 2012-06-04 07:16 @344

Re: Expresiones Regulares de Perl en CGI

Notapor Skull118 » 2014-02-26 17:34 @774

Estos son los errores que me da, compañero, efectivamente estoy sobre Windows (prefiero Linux pero no puedo escoger aquí :( Mientras tanto hago lo que puedo con lo que tengo.

Sintáxis: [ Descargar ] [ Ocultar ]
  1. [Wed Feb 26 16:14:44 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  2. [Wed Feb 26 16:14:44 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  3. [Wed Feb 26 16:14:47 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  4. [Wed Feb 26 16:14:47 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  5. [Wed Feb 26 16:15:42 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  6. [Wed Feb 26 16:15:42 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  7. [Wed Feb 26 16:17:33 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  8. [Wed Feb 26 16:17:33 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  9. [Wed Feb 26 16:17:46 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  10. [Wed Feb 26 16:17:46 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  11. [Wed Feb 26 16:21:35 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  12. [Wed Feb 26 16:21:35 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  13. [Wed Feb 26 16:23:42 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  14. [Wed Feb 26 16:23:42 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  15. [Wed Feb 26 16:24:12 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  16. [Wed Feb 26 16:24:12 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
  17. [Wed Feb 26 16:29:13 2014] [notice] Parent: Received shutdown signal -- Shutting down the server. 
  18. [Wed Feb 26 16:29:13 2014] [notice] Child 10116: Exit event signaled. Child process is ending. 
  19. [Wed Feb 26 16:29:14 2014] [notice] Child 10116: Released the start mutex 
  20. [Wed Feb 26 16:29:15 2014] [notice] Child 10116: All worker threads have exited. 
  21. [Wed Feb 26 16:29:15 2014] [notice] Child 10116: Child process is exiting 
  22. [Wed Feb 26 16:29:15 2014] [notice] Parent: Child process exited successfully. 
  23. [Wed Feb 26 16:29:21 2014] [notice] Apache/2.2.17 (Win32) PHP/5.3.4 configured -- resuming normal operations 
  24. [Wed Feb 26 16:29:21 2014] [notice] Server built: Oct 24 2010 13:33:15 
  25. [Wed Feb 26 16:29:21 2014] [notice] Parent: Created child process 10168 
  26. [Wed Feb 26 16:29:21 2014] [notice] Child 10168: Child process is running 
  27. [Wed Feb 26 16:29:21 2014] [notice] Child 10168: Acquired the start mutex. 
  28. [Wed Feb 26 16:29:21 2014] [notice] Child 10168: Starting 64 worker threads. 
  29. [Wed Feb 26 16:29:21 2014] [notice] Child 10168: Starting thread to listen on port 80. 
  30. [Wed Feb 26 16:29:31 2014] [error] [client 127.0.0.1] C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL is not executable; ensure interpreted scripts have "#!" first line 
  31. [Wed Feb 26 16:29:31 2014] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/wamp/bin/apache/Apache2.2.17/cgi-bin/REVISAR_DCMS.PL 
Skull118
Perlero nuevo
Perlero nuevo
 
Mensajes: 53
Registrado: 2013-03-21 13:38 @610

Re: Expresiones Regulares de Perl en CGI

Notapor explorer » 2014-02-26 17:52 @786

La línea 4 tampoco es Perl. Es más... algunas líneas están destrozadas, en el sentido de que uno o más caracteres están cambiados de sitio. Algo te ha pasado a la hora de copiar el código.

El programa quedaría así:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!C:/Perl64/bin/perl.exe
  2. use strict;
  3. use warnings;
  4.  
  5. print("Content-type: text/html\n\n");
  6.  
  7. for my $a (glob("*.TXT")) {           # para todos los archivos '*.TXT'
  8.     my $ar = $a;                      # nombre del archivo
  9.     my $ar =~ s/\s*$//g;              # quitarle los espacios en blanco del final del nombre
  10.  
  11.     if ($a =~ m/^TV/) {               # si el nombre original del archivo empieza por 'TV'
  12.         print "<script language='javascript'>alert('NO SÉ CUÁL PROCEDIMIENTO CORRERÍA CON EL ARCHIVO " . $ar . "');</script>";
  13.     }
  14.     else {
  15.         print "<script language='javascript'>alert('LLAMARÍA AL SCRIPT DE TV CON EL ARCHIVO "          . $ar . "');</script>";
  16.     }
  17. }
  18.  
  19. exit;
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

El mensaje de error dice que la primera línea debe empezar por '#!', lo cual es raro, ya que en Windows, no debería importar. Será cosa de usar el WAMP...
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: Expresiones Regulares de Perl en CGI

Notapor Skull118 » 2014-02-27 16:50 @743

Interesante respuesta, explorer, me he dado cuenta que cambia EN GRAN MANERA, la forma de programar en aplicación de escritorio (por así decirlo) y en aplicación de servidor, razón por la cual preguntaba ¿dónde puedo encontrar documentación que me permita, aprender la sintaxis básica, debido a que en el lado de "escritorio" por así decirlo, no me presenta ningún error?

De antemano, muchas gracias.
Skull118
Perlero nuevo
Perlero nuevo
 
Mensajes: 53
Registrado: 2013-03-21 13:38 @610

Siguiente

Volver a Básico

¿Quién está conectado?

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

cron