SlideShare a Scribd company logo
* Before we start...



$ perldoc



#!/usr/bin/perl


use strict;




* Datos y Operadores

   * Datos Escalares

        * Strings

Datos de texto o binarios, sin significado para el programa, delimitados típicamente por comillas sencillas o dobles:

my $world = 'Mundo';
my $escaped = 'Dan O'Bannon';
my $backslash = '';

                     * Comillas dobles

my $newline = "n";

my $tab = "t";

my $input = "hellonworld!";

my $data = "08029t25";

my $data = "08029,"Eixample Esquerra"";

my $data = qq{08029,"Eixample Esquerra"};

                     * Interpolación

my $hello = "Hola, $world!n";
my $hello = qq{Hola, "$world"!n};

                     * Funciones típicas de cadena

      length EXPR

      substr EXPR,OFFSET,LENGTH,REPLACEMENT
      substr EXPR,OFFSET,LENGTH
      substr EXPR,OFFSET

      index STR,SUBSTR,POSITION
      index STR,SUBSTR

      Functions for SCALARs or strings
          "chomp", "chop", "chr", "crypt", "hex", "index", "lc", "lcfirst",
          "length", "oct", "ord", "pack", "q//", "qq//", "reverse", "rindex",
          "sprintf", "substr", "tr///", "uc", "ucfirst", "y///"

      => Más cuando hablemos de expresiones regulares

        * Números

$ perldoc perlnumber

            $n   =   1234;               #   decimal integer
            $n   =   0b1110011;          #   binary integer
            $n   =   01234;              #   *octal* integer
            $n   =   0x1234;             #   hexadecimal integer
            $n   =   12.34e−56;          #   exponential notation
            $n   =   "−12.34e56";        #   number specified as a string
            $n   =   "1234";             #   number specified as a string

   * Hashes, Listas y Arreglos




                                                              1 de 5
@ Arreglo



          my @author;

          $author[0] = 'Asimov';
          $author[1] = 'Bear';
          $author[2] = 'King';

          print "First author is " . $author[0] . "n";

          print "Last author is " . $author[$#author] . "n";

          print "Last author is " . $author[-1] . "n";

          print "There are " . @author . " authorsn";


          my @num = (0..10);
          my @a = (@b,@c);



                     * Funciones típicas para arreglos

         sort SUBNAME LIST
         sort BLOCK LIST
         sort LIST

         grep BLOCK LIST
         grep EXPR,LIST

         join EXPR,LIST

         split /PATTERN/,EXPR,LIMIT
         split /PATTERN/,EXPR
         split /PATTERN/

# ++$learn
$ perldoc List::Util



% Hash

          my %name;

          $name{'Asimov'} = 'Isaac';
          $name{'Bear'} = 'Greg';
          $name{'King'} = 'Stephen';

                     * Funciones típicas para hashes

         keys HASH

         values HASH


   print "Authors are ".keys(%name)."n";


   * Identificadores, variables y su notación

              Notación

Las variables son precedidas de un sigil que indica el tipo de valor de la variable:
$ Escalar
@ Arreglo
% Hash
e.g.
my($nombre, @nombre, %nombre);

Para acceder el elemento de un arreglo o hash, se utiliza el sigil escalar:
$nombre{$id} = 'Ann';
$nombre[$pos] = 'Ben';

Es posible acceder múltiples valores al mismo tiempo utilizando el sigil de arreglo:

@nombre{@keys} = @values;




                                                          2 de 5
@suspendidos = @nombre[@selected];

@authors =("Asimov","Bear","King");

@authors = qw(Asimov Bear King);



           Variables especiales

$ perldoc perlvar
$ perldoc English

                  @ARGV
                  @INC
                  %ENV
                  %SIG
                  $@
                  @_
                  $_



   * I/O

           * Consola

           STDIN
           STDOUT
           STDERR

           e.g.

           print STDERR "This is a debug messagen";

#!/usr/bin/perl
use strict;
use Chatbot::Eliza;

my $eliza = Chatbot::Eliza->new();
while(<STDIN>) {
        chomp;
        print "> ".$eliza->transform($_),"n";
}




           * Ficheros

$ perldoc -f open
$ perldoc perlopentut

           #
           # Reading from a file
           #

           # Please don't do this!
           open(FILE,"<$file");

           # Do *this* instead
           open my $fh, '<', 'filename' or die "Cannot read '$filename': $!n";
               while (<$fh>) {
                       chomp; say "Read a line '$_'";
               }


                  #
                  # Writing to a file
                  #

               use autodie;
               open my $out_fh, '>', 'output_file.txt';
               print $out_fh "Here's a line of textn";
               say     $out_fh "... and here's another";
           close $out_fh;

           # $fh->autoflush( 1 );




                                                       3 de 5
#
                   # There's much more!
                   # :mmap, :utf8, :crlf, ...
                   #

          open($fh, ">:utf8", "data.utf");
          print $fh $out;
          close($fh);

#   ++$learn
$   perldoc perlio
$   perldoc IO::Handle
$   perldoc IO::File


     * Operadores y su precedencia
         ( y su asociatividad ( y su arity ( y su fixity ) ) )

$ perldoc perlop

             left          terms and list operators (leftward)
             left          −>
             nonassoc      ++ −−
             right         **
             right         ! ~  and unary + and −
             left          =~ !~
             left          * / % x
             left          + − .
             left          << >>
             nonassoc      named unary operators
             nonassoc      < > <= >= lt gt le ge
             nonassoc      == != <=> eq ne cmp ~~
             left          &
             left          | ^
             left          &&
             left          || //
             nonassoc      .. ...
             right         ?:
             right         = += −= *= etc.
             left          , =>
             nonassoc      list operators (rightward)
             right         not
             left          and
             left          or xor



                   => Atencion!

             print ( ($foo & 255) + 1, "n");

             print ++$foo;

                   * Operadores
                           * Numericos
                           * String
                           * Logicos
                           * Bitwise
                           * Especiales

     * Estructuras de Control

             if (EXPR) BLOCK
             if (EXPR) BLOCK else BLOCK
             if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
             LABEL while (EXPR) BLOCK
             LABEL while (EXPR) BLOCK continue BLOCK
             LABEL until (EXPR) BLOCK
             LABEL until (EXPR) BLOCK continue BLOCK
             LABEL for (EXPR; EXPR; EXPR) BLOCK
             LABEL foreach VAR (LIST) BLOCK
             LABEL foreach VAR (LIST) BLOCK continue BLOCK
             LABEL BLOCK continue BLOCK

                   e.g.

                        for(my $i=0; $i<@author; ++$i) {
                             print $i.": ".$author[$i]."n";
                        }




                                                           4 de 5
for(0..$#author) {
                       print $_.": ".$author[$_]."n";
          }

                          foreach my $i (0..$#author) {
                          print $i.": ".$author[$i]."n";
                          }

                             for(0..1000000) {
                                     print $_,"n";
                             }

           while(<$fh>) {
                        # Skip comments
                        next if /^#/;
                        ...
           }

        * Modificadores

           if EXPR
           unless EXPR
           while EXPR
           until EXPR
           foreach LIST

           e.g.
             print "Value is $valn" if $debug;
             print $i++ while $i <= 10;

   Contexto

        * Void

                  find_chores();

        * Lista

                             my @all_results = find_chores();
                             my ($single_element)    = find_chores();
                             process_list_of_results( find_chores() );

                  my ($self,@args) = @_;

        * Escalar

                             print "Hay ".@author." autoresn";
                             print "Hay ".scalar(@author)." autoresn";

# ++$learn
$ perldoc -f wantarray

                  * Numerico

                             my $a   = "a";
                             my $b   = "b";
                             print   "a is equal to b " if ($a==$b); # Really?
                             print   "a is equal to b " if ($a eq $b);

                  * Cadena

                             my $a = 2;
                             print "The number is ".$a."n";

                  * Booleano
                          my $a = 0;
                          print "a is truen" if $a;
                          $a = 1;
                          print "a is truen" if $a;
                          $a = "a";
                          print "a is truen" if $a;



                  my $numeric_x = 0 + $x; # forces numeric context
                  my $stringy_x = '' . $x; # forces string context
                  my $boolean_x = !!$x; # forces boolean context




                                                             5 de 5

More Related Content

What's hot

Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
Rafael Dohms
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
AbhishekSharma2958
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
Andrew Shitov
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
tutorial7
tutorial7tutorial7
tutorial7
tutorialsruby
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
brian d foy
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
Radek Benkel
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
Chad Gray
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
brian d foy
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
Sérgio Rafael Siqueira
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
Sean Cribbs
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
Radek Benkel
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenics
Giorgio Cefaro
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
Kris Wallsmith
 

What's hot (17)

Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
tutorial7
tutorial7tutorial7
tutorial7
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
PHP object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenics
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 

Viewers also liked

Real Value in Real Time: MongoDB-based Analytics at TeachStreet
Real Value in Real Time: MongoDB-based Analytics at TeachStreetReal Value in Real Time: MongoDB-based Analytics at TeachStreet
Real Value in Real Time: MongoDB-based Analytics at TeachStreet
TeachStreet
 
sport maakt jonger
sport maakt jongersport maakt jonger
sport maakt jongerJoke
 
Instructional Design for the Semantic Web
Instructional Design for the Semantic WebInstructional Design for the Semantic Web
Instructional Design for the Semantic Web
guest649a93
 
Evolving a strategy for Emerging and startup companies
Evolving a strategy for Emerging and startup companiesEvolving a strategy for Emerging and startup companies
Evolving a strategy for Emerging and startup companies
guest716604
 
PresentacióN Informe Taller De Fotografia
PresentacióN Informe Taller De Fotografia PresentacióN Informe Taller De Fotografia
PresentacióN Informe Taller De Fotografia Leonel Vasquez
 
From idea to exit
From idea to exitFrom idea to exit
From idea to exit
Natalie Downe
 
Cascao Hydropolitics TWM Lake Victoria 2009 (II)
Cascao Hydropolitics TWM Lake Victoria 2009 (II)Cascao Hydropolitics TWM Lake Victoria 2009 (II)
Cascao Hydropolitics TWM Lake Victoria 2009 (II)
Ana Cascao
 
Notetaking
NotetakingNotetaking
Notetaking
colwilliamson
 
Frases Célebres
Frases CélebresFrases Célebres
Frases Célebres
walll
 
Indonesian Photos 07
Indonesian Photos   07Indonesian Photos   07
Indonesian Photos 07
sutrisno2629
 
Land 'Grabbing' in the Nile Basin and implications for the regional water sec...
Land 'Grabbing' in the Nile Basin and implications for the regional water sec...Land 'Grabbing' in the Nile Basin and implications for the regional water sec...
Land 'Grabbing' in the Nile Basin and implications for the regional water sec...
Ana Cascao
 
Cascao Leipzig Waterscapes Nile Basin
Cascao Leipzig Waterscapes Nile BasinCascao Leipzig Waterscapes Nile Basin
Cascao Leipzig Waterscapes Nile Basin
Ana Cascao
 
A Touching Story4007
A Touching Story4007A Touching Story4007
A Touching Story4007
sutrisno2629
 
Las vanguardias históricas
Las vanguardias históricasLas vanguardias históricas
Las vanguardias históricas
Alfredo Rivero
 
From Idea to Exit, the story of our startup
From Idea to Exit, the story of our startupFrom Idea to Exit, the story of our startup
From Idea to Exit, the story of our startup
Natalie Downe
 
Programació orientada a objectes en Perl
Programació orientada a objectes en PerlProgramació orientada a objectes en Perl
Programació orientada a objectes en PerlAlex Muntada Duran
 
Benvinguda al Curs d'introducció a Perl 2011
Benvinguda al Curs d'introducció a Perl 2011Benvinguda al Curs d'introducció a Perl 2011
Benvinguda al Curs d'introducció a Perl 2011
Alex Muntada Duran
 
Erik Scarcia
Erik Scarcia Erik Scarcia
Erik Scarcia
Erik Scarcia
 

Viewers also liked (20)

Real Value in Real Time: MongoDB-based Analytics at TeachStreet
Real Value in Real Time: MongoDB-based Analytics at TeachStreetReal Value in Real Time: MongoDB-based Analytics at TeachStreet
Real Value in Real Time: MongoDB-based Analytics at TeachStreet
 
sport maakt jonger
sport maakt jongersport maakt jonger
sport maakt jonger
 
Kansberekening
KansberekeningKansberekening
Kansberekening
 
Instructional Design for the Semantic Web
Instructional Design for the Semantic WebInstructional Design for the Semantic Web
Instructional Design for the Semantic Web
 
Evolving a strategy for Emerging and startup companies
Evolving a strategy for Emerging and startup companiesEvolving a strategy for Emerging and startup companies
Evolving a strategy for Emerging and startup companies
 
PresentacióN Informe Taller De Fotografia
PresentacióN Informe Taller De Fotografia PresentacióN Informe Taller De Fotografia
PresentacióN Informe Taller De Fotografia
 
From idea to exit
From idea to exitFrom idea to exit
From idea to exit
 
Cascao Hydropolitics TWM Lake Victoria 2009 (II)
Cascao Hydropolitics TWM Lake Victoria 2009 (II)Cascao Hydropolitics TWM Lake Victoria 2009 (II)
Cascao Hydropolitics TWM Lake Victoria 2009 (II)
 
Notetaking
NotetakingNotetaking
Notetaking
 
Frases Célebres
Frases CélebresFrases Célebres
Frases Célebres
 
Indonesian Photos 07
Indonesian Photos   07Indonesian Photos   07
Indonesian Photos 07
 
Land 'Grabbing' in the Nile Basin and implications for the regional water sec...
Land 'Grabbing' in the Nile Basin and implications for the regional water sec...Land 'Grabbing' in the Nile Basin and implications for the regional water sec...
Land 'Grabbing' in the Nile Basin and implications for the regional water sec...
 
Cascao Leipzig Waterscapes Nile Basin
Cascao Leipzig Waterscapes Nile BasinCascao Leipzig Waterscapes Nile Basin
Cascao Leipzig Waterscapes Nile Basin
 
A Touching Story4007
A Touching Story4007A Touching Story4007
A Touching Story4007
 
030413
030413030413
030413
 
Las vanguardias históricas
Las vanguardias históricasLas vanguardias históricas
Las vanguardias históricas
 
From Idea to Exit, the story of our startup
From Idea to Exit, the story of our startupFrom Idea to Exit, the story of our startup
From Idea to Exit, the story of our startup
 
Programació orientada a objectes en Perl
Programació orientada a objectes en PerlProgramació orientada a objectes en Perl
Programació orientada a objectes en Perl
 
Benvinguda al Curs d'introducció a Perl 2011
Benvinguda al Curs d'introducció a Perl 2011Benvinguda al Curs d'introducció a Perl 2011
Benvinguda al Curs d'introducció a Perl 2011
 
Erik Scarcia
Erik Scarcia Erik Scarcia
Erik Scarcia
 

Similar to Dades i operadors

perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 
Subroutines
SubroutinesSubroutines
tutorial7
tutorial7tutorial7
tutorial7
tutorialsruby
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
tutorialsruby
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
tutorialsruby
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
worr1244
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
Ben Pope
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
Varadharajan Mukundan
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon
 
Scalar data types
Scalar data typesScalar data types
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
brian d foy
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
Viktor Turskyi
 

Similar to Dades i operadors (20)

perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Scripting3
Scripting3Scripting3
Scripting3
 
Subroutines
SubroutinesSubroutines
Subroutines
 
tutorial7
tutorial7tutorial7
tutorial7
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
 

More from Alex Muntada Duran

Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)
Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)
Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)
Alex Muntada Duran
 
Desenvolupament al projecte Debian
Desenvolupament al projecte DebianDesenvolupament al projecte Debian
Desenvolupament al projecte Debian
Alex Muntada Duran
 
REST in theory
REST in theoryREST in theory
REST in theory
Alex Muntada Duran
 
Orientació a objectes amb Moose
Orientació a objectes amb MooseOrientació a objectes amb Moose
Orientació a objectes amb MooseAlex Muntada Duran
 
Cloenda del Curs d'introducció a Perl 2011
Cloenda del Curs d'introducció a Perl 2011Cloenda del Curs d'introducció a Perl 2011
Cloenda del Curs d'introducció a Perl 2011Alex Muntada Duran
 
Modern Perl Toolchain
Modern Perl ToolchainModern Perl Toolchain
Modern Perl Toolchain
Alex Muntada Duran
 
dh-make-perl
dh-make-perldh-make-perl
dh-make-perl
Alex Muntada Duran
 

More from Alex Muntada Duran (9)

Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)
Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)
Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)
 
Desenvolupament al projecte Debian
Desenvolupament al projecte DebianDesenvolupament al projecte Debian
Desenvolupament al projecte Debian
 
REST in theory
REST in theoryREST in theory
REST in theory
 
Comiat del curs de Perl
Comiat del curs de PerlComiat del curs de Perl
Comiat del curs de Perl
 
Benvinguda al curs de Perl
Benvinguda al curs de PerlBenvinguda al curs de Perl
Benvinguda al curs de Perl
 
Orientació a objectes amb Moose
Orientació a objectes amb MooseOrientació a objectes amb Moose
Orientació a objectes amb Moose
 
Cloenda del Curs d'introducció a Perl 2011
Cloenda del Curs d'introducció a Perl 2011Cloenda del Curs d'introducció a Perl 2011
Cloenda del Curs d'introducció a Perl 2011
 
Modern Perl Toolchain
Modern Perl ToolchainModern Perl Toolchain
Modern Perl Toolchain
 
dh-make-perl
dh-make-perldh-make-perl
dh-make-perl
 

Recently uploaded

How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
Celine George
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
Kalna College
 
Ch-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdfCh-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdf
lakshayrojroj
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
7DFarhanaMohammed
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
sonukumargpnirsadhan
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Kalna College
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
andagarcia212
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 

Recently uploaded (20)

How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
 
Ch-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdfCh-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdf
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 

Dades i operadors

  • 1. * Before we start... $ perldoc #!/usr/bin/perl use strict; * Datos y Operadores * Datos Escalares * Strings Datos de texto o binarios, sin significado para el programa, delimitados típicamente por comillas sencillas o dobles: my $world = 'Mundo'; my $escaped = 'Dan O'Bannon'; my $backslash = ''; * Comillas dobles my $newline = "n"; my $tab = "t"; my $input = "hellonworld!"; my $data = "08029t25"; my $data = "08029,"Eixample Esquerra""; my $data = qq{08029,"Eixample Esquerra"}; * Interpolación my $hello = "Hola, $world!n"; my $hello = qq{Hola, "$world"!n}; * Funciones típicas de cadena length EXPR substr EXPR,OFFSET,LENGTH,REPLACEMENT substr EXPR,OFFSET,LENGTH substr EXPR,OFFSET index STR,SUBSTR,POSITION index STR,SUBSTR Functions for SCALARs or strings "chomp", "chop", "chr", "crypt", "hex", "index", "lc", "lcfirst", "length", "oct", "ord", "pack", "q//", "qq//", "reverse", "rindex", "sprintf", "substr", "tr///", "uc", "ucfirst", "y///" => Más cuando hablemos de expresiones regulares * Números $ perldoc perlnumber $n = 1234; # decimal integer $n = 0b1110011; # binary integer $n = 01234; # *octal* integer $n = 0x1234; # hexadecimal integer $n = 12.34e−56; # exponential notation $n = "−12.34e56"; # number specified as a string $n = "1234"; # number specified as a string * Hashes, Listas y Arreglos 1 de 5
  • 2. @ Arreglo my @author; $author[0] = 'Asimov'; $author[1] = 'Bear'; $author[2] = 'King'; print "First author is " . $author[0] . "n"; print "Last author is " . $author[$#author] . "n"; print "Last author is " . $author[-1] . "n"; print "There are " . @author . " authorsn"; my @num = (0..10); my @a = (@b,@c); * Funciones típicas para arreglos sort SUBNAME LIST sort BLOCK LIST sort LIST grep BLOCK LIST grep EXPR,LIST join EXPR,LIST split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ # ++$learn $ perldoc List::Util % Hash my %name; $name{'Asimov'} = 'Isaac'; $name{'Bear'} = 'Greg'; $name{'King'} = 'Stephen'; * Funciones típicas para hashes keys HASH values HASH print "Authors are ".keys(%name)."n"; * Identificadores, variables y su notación Notación Las variables son precedidas de un sigil que indica el tipo de valor de la variable: $ Escalar @ Arreglo % Hash e.g. my($nombre, @nombre, %nombre); Para acceder el elemento de un arreglo o hash, se utiliza el sigil escalar: $nombre{$id} = 'Ann'; $nombre[$pos] = 'Ben'; Es posible acceder múltiples valores al mismo tiempo utilizando el sigil de arreglo: @nombre{@keys} = @values; 2 de 5
  • 3. @suspendidos = @nombre[@selected]; @authors =("Asimov","Bear","King"); @authors = qw(Asimov Bear King); Variables especiales $ perldoc perlvar $ perldoc English @ARGV @INC %ENV %SIG $@ @_ $_ * I/O * Consola STDIN STDOUT STDERR e.g. print STDERR "This is a debug messagen"; #!/usr/bin/perl use strict; use Chatbot::Eliza; my $eliza = Chatbot::Eliza->new(); while(<STDIN>) { chomp; print "> ".$eliza->transform($_),"n"; } * Ficheros $ perldoc -f open $ perldoc perlopentut # # Reading from a file # # Please don't do this! open(FILE,"<$file"); # Do *this* instead open my $fh, '<', 'filename' or die "Cannot read '$filename': $!n"; while (<$fh>) { chomp; say "Read a line '$_'"; } # # Writing to a file # use autodie; open my $out_fh, '>', 'output_file.txt'; print $out_fh "Here's a line of textn"; say $out_fh "... and here's another"; close $out_fh; # $fh->autoflush( 1 ); 3 de 5
  • 4. # # There's much more! # :mmap, :utf8, :crlf, ... # open($fh, ">:utf8", "data.utf"); print $fh $out; close($fh); # ++$learn $ perldoc perlio $ perldoc IO::Handle $ perldoc IO::File * Operadores y su precedencia ( y su asociatividad ( y su arity ( y su fixity ) ) ) $ perldoc perlop left terms and list operators (leftward) left −> nonassoc ++ −− right ** right ! ~ and unary + and − left =~ !~ left * / % x left + − . left << >> nonassoc named unary operators nonassoc < > <= >= lt gt le ge nonassoc == != <=> eq ne cmp ~~ left & left | ^ left && left || // nonassoc .. ... right ?: right = += −= *= etc. left , => nonassoc list operators (rightward) right not left and left or xor => Atencion! print ( ($foo & 255) + 1, "n"); print ++$foo; * Operadores * Numericos * String * Logicos * Bitwise * Especiales * Estructuras de Control if (EXPR) BLOCK if (EXPR) BLOCK else BLOCK if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK LABEL while (EXPR) BLOCK LABEL while (EXPR) BLOCK continue BLOCK LABEL until (EXPR) BLOCK LABEL until (EXPR) BLOCK continue BLOCK LABEL for (EXPR; EXPR; EXPR) BLOCK LABEL foreach VAR (LIST) BLOCK LABEL foreach VAR (LIST) BLOCK continue BLOCK LABEL BLOCK continue BLOCK e.g. for(my $i=0; $i<@author; ++$i) { print $i.": ".$author[$i]."n"; } 4 de 5
  • 5. for(0..$#author) { print $_.": ".$author[$_]."n"; } foreach my $i (0..$#author) { print $i.": ".$author[$i]."n"; } for(0..1000000) { print $_,"n"; } while(<$fh>) { # Skip comments next if /^#/; ... } * Modificadores if EXPR unless EXPR while EXPR until EXPR foreach LIST e.g. print "Value is $valn" if $debug; print $i++ while $i <= 10; Contexto * Void find_chores(); * Lista my @all_results = find_chores(); my ($single_element) = find_chores(); process_list_of_results( find_chores() ); my ($self,@args) = @_; * Escalar print "Hay ".@author." autoresn"; print "Hay ".scalar(@author)." autoresn"; # ++$learn $ perldoc -f wantarray * Numerico my $a = "a"; my $b = "b"; print "a is equal to b " if ($a==$b); # Really? print "a is equal to b " if ($a eq $b); * Cadena my $a = 2; print "The number is ".$a."n"; * Booleano my $a = 0; print "a is truen" if $a; $a = 1; print "a is truen" if $a; $a = "a"; print "a is truen" if $a; my $numeric_x = 0 + $x; # forces numeric context my $stringy_x = '' . $x; # forces string context my $boolean_x = !!$x; # forces boolean context 5 de 5