1 / 27

PERL

PERL. Ferrer Camacho. P ractical E xtraction and R eport L anguage. Lenguajes de Programación. Dra. Ana Lilia Laureano Cruces. Temas a abordar. Historia Características del lenguaje. Historia de Perl 0.000. Presentación del lenguaje Perl por Larry Wall a sus socios en 1986.

Télécharger la présentation

PERL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PERL Ferrer Camacho Practical Extraction and Report Language Lenguajes de Programación Dra. Ana Lilia Laureano Cruces

  2. Temas a abordar • Historia • Características del lenguaje Humberto Ferrer C.

  3. Historia de Perl 0.000 Presentación del lenguaje Perl por Larry Wall a sus socios en 1986 Humberto Ferrer C.

  4. Historia de Perl 1.000 Fue creado por Larry Wall en 1987 Originalmente fue creado para la manipulación de textos. Perl is a interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It's also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Humberto Ferrer C. 18/dic

  5. Historia de Perl 2.000 El 5 de enero del 1988 se libero • Se integraron las expresiones regulares • El uso de subrutinas • Recursividad • Manejo de archivos • Integración de foreach • Asignación múltiple Humberto Ferrer C.

  6. Historia de Perl 3.000 El 18 de octubre del 1989 se libero Principalmente se ocupaba para administración Paso por referencia a las subrutinas Incorporación del depurador Se pueden cortar las listas Incremento en las funciones. (mkdir, rmdir, getppid …) Humberto Ferrer C.

  7. Historia de Perl 4.000 El 21 de marzo del 1991 se libero The first edition of Programming Perl Utilización para WEB Incorporación a Linux Humberto Ferrer C.

  8. Historia de Perl 5.000 El 18 de octubre del 1994 se libero Orientación a Objetos El uso de :: como delimitador de paquete Incremento en las funciones: abs(), chomp(), glob(),… Se introduce => como sinónimo de comas Se crea CPAN (Comprehensive Perl Archive Network) Humberto Ferrer C.

  9. Paradigma "Hay más de una forma de hacerlo". Larry Wall, autor del lenguaje de programación Perl. Perl no establece ninguna paradigma de programación (de hecho, no se puede decir que sea orientado a objetos, modular o estructurado aun cuando soporta directamente todos estos paradigmas) Humberto Ferrer C.

  10. Características • Flexibilidad • Claridad • Portabilidad Humberto Ferrer C.

  11. Algo de programación • Variables • Estructuras de control • Expresiones regulares • Subrutinas • Módulos • Orientación a objetos Humberto Ferrer C.

  12. Funciones de Perl -X,abs, accept, alarm, atan2, bind, binmode, bless, caller, chdir, chmod, chomp, chop, chown, chr, chroot, close, closedir, connect, continue, cos, crypt, dbmclose, dbmopen, defined, delete, die, do, dump, each, endgrent, endhostent, endnetent, endprotoent, endpwent, endservent, eof, eval, exec, exists, exit, exp, fcntl, fileno, flock, fork, format, formline, getc, getgrent, getgrgid, getgrnam, gethostbyaddr, gethostbyname, gethostent, getlogin, getnetbyaddr, getnetbyname, getnetent, getpeername, getpgrp, getppid, getpriority, getprotobyname, getprotobynumber, getprotoent, getpwent, getpwnam, getpwuid, getservbyname, getservbyport, getservent, getsockname, getsockopt, glob, gmtime, goto, grep, hex,import, index, int, ioctl, join, keys, kill, last, lc, lcfirst, length, link, listen, local, localtime, lock, log, lstat, m, map, mkdir, msgctl, msgget, msgrcv, msgsnd, my, next, no, oct, open, opendir, ord, our, pack, package, pipe, pop, pos, print, printf, prototype, push, q, qq, qr, quotemeta, qw, qx, rand, read, readdir, readline, readlink, readpipe, recv, redo, ref, rename, require, reset, return, reverse, rewinddir, rindex, rmdir, s, scalar, seek, seekdir, select, semctl, semget, semop, send, setgrent, sethostent, setnetent, setpgrp, setpriority, setprotoent, setpwent, setservent, setsockopt, shift, shmctl, shmget, shmread, shmwrite, shutdown, sin, sleep, socket, socketpair, sort, splice, split, sprintf, sqrt, srand, stat, study, sub, substr, symlink, syscall, sysopen, sysread, sysseek, system, syswrite, tell, telldir, tie, tied, time, times, tr, truncate, uc, ucfirst, umask, undef, unlink, unpack, unshift, untie, use, utime, values, vec, wait, waitpid, wantarray, warn, write, y Humberto Ferrer C.

  13. Variables • Escalares • Siempre inician con $ y un caracter • Arreglos • Siempre inician con @ y un caracter • Arreglos asociados • Siempre inician con % y un caracter No es necesario predeclarar las variables, se pueden empezar a usar directamente en las expresiones. Humberto Ferrer C.

  14. Variables especiales Existen dos variables muy importantes en Perl las variables anónimas • $_ • @_ Y sirven para el paso de parámetros. Humberto Ferrer C.

  15. Operadores de comparación Humberto Ferrer C.

  16. Estructuras de control • if/unless • print “hola” if(true); • unless (false) { print “hola”; } • while/until • while(true) {print “”}; • for • for($i = 1; $i <= 10; $i++) { print "$i "; } • foreach • @a = (1,2,3,4,5); foreach $b (@a) {$b *=3; print $b; } Humberto Ferrer C.

  17. Subrutinas Para definir una subrutina o función se utiliza la palabra sub sub suma { $valor0=shift @_; $valor1=shift @_; return $valor1+$valor0; } … print suma(1,2); Humberto Ferrer C.

  18. Expresiones regulares Una expresión regular es una forma de expresar gramaticalmente la estructura de cualquier cadena alfanumérica. Y se realiza mediante el operador // Modificadores de expresiones regulares Humberto Ferrer C.

  19. Módulos Un módulo proporciona una manera de empaquetar el código de Perl para reusarse. #!/usr/local/bin/perl ##### Modulo.pm use File; sub funcion { … } 1; Humberto Ferrer C.

  20. Orientación a objetos Un objeto de Perl es una modificación de los módulos a los cuales se les da una referencia a las clases. #!/usr/local/bin/perl ## objeto.pm package objeto; sub new { #contructor my $self = {}; $self->{METODOS} = undef; bless($self); return $self; } sub DESTROY {# Destructor. print "Destruido.\n"; } sub medotodos { # metoros my $self = shift; if (@_) { $self->{METODOS} = shift; ... } return $self->{METODOS}; } 1; Humberto Ferrer C.

  21. CPAM CPAN's 7240 modules distributions in alphabetical order by modules contained in the distributions Wed Nov 24 16:09:56 2004 GMT Entre algunas categorias:Algorithm, AltaVista, Apache, ASP, Audio, Business, CAD , Calendar , CGI , Chemistry , Crypt , DateTime , Email , Event , Excel , Exporter , Gtk … Humberto Ferrer C.

  22. Ejemplo palindrome #!/usr/bin/perl # Palindrome.pl # Humberto Ferrer C. @pila=@lista =''; print "Ingrese una palabra para verificar si es palindrome\n"; $entrada=<STDIN>; chop($entrada); @lista=split('',$entrada); if($#lista%2) { for($i=0;$i<$#lista/2;$i++) { push @pila, $lista[$i]; print "@pila \n"; } for(;$i<$#lista+1;$i++) { print "@pila <-" . $lista[$i]. "\n"; $l=pop @pila; if($l ne $lista[$i]) { print "No es palindrome\n"; exit; } } print "si fue\n"; } else { for($i=0;$i<$#lista/2;$i++) { push @pila, $lista[$i]; printl ; } $i++; for(;$i<$#lista+1;$i++) { print "@pila <-" . $lista[$i]. "\n"; $l=pop @pila; if($l ne $lista[$i]) { printl "No es palindrome"; exit; } } printl "si fue"; } Humberto Ferrer C.

  23. Ventajas Aunque desarrollado originalmente en un entorno UNIX, actualmente hay versiones para casi todos los sistemas operativos ya que esta programado en C. Humberto Ferrer C.

  24. Ventajas Cuando ejecutamos un programa en Perl, se compila el código fuente a un código intermedio en memoria, se le optimiza pero es ejecutado por un motor, como si se tratara de un intérprete. El resultado final, es que utilizamos algo que se comporta como un intérprete, pero que tiene un rendimiento comparativo al de programas compilados Humberto Ferrer C.

  25. Desventajas • Poco tipificado • No es recomendado para las siguientes tareas: • Sistemas de tiempo real • Desarrollo de bajo nivel del sistema operativo que trabajen con controladores • Aplicaciones de memoria compartida de procesos o aplicaciones extremadamente largas. Humberto Ferrer C.

  26. Algunas aplicaciones • Sistemas operativos • Perl/Linux http://perllinux.sourceforge.net/ • Manipulación de textos • Páginas dinámicas CGI • Administración UNIX Humberto Ferrer C.

  27. Bibliografía • Programming Perl, por Larry Wall y otros • www.perl.org • www.cpam.com Humberto Ferrer C.

More Related