SlideShare a Scribd company logo
1 of 5
Download to read offline
* 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

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 itRafael Dohms
 
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 6Andrew Shitov
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trialbrian d foy
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPChad Gray
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangSean 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 object calisthenics
PHP object calisthenicsPHP object calisthenics
PHP object calisthenicsGiorgio 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 TeachStreetTeachStreet
 
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 Webguest649a93
 
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 companiesguest716604
 
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
 
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
 
Frases Célebres
Frases CélebresFrases Célebres
Frases Célebreswalll
 
Indonesian Photos 07
Indonesian Photos   07Indonesian Photos   07
Indonesian Photos 07sutrisno2629
 
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 BasinAna Cascao
 
A Touching Story4007
A Touching Story4007A Touching Story4007
A Touching Story4007sutrisno2629
 
Las vanguardias históricas
Las vanguardias históricasLas vanguardias históricas
Las vanguardias históricasAlfredo 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 startupNatalie 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 2011Alex Muntada Duran
 

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 (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

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

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

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