SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
A Brief Pocket Reference for Perl Programming
This pocket reference was created to help the author to refresh Perl,
presumably aiming at an intermediate programmer or advanced. This pocket
reference is mainly based on several anonymous resources found on the
Internet. It’s free to distribute/modify. Any inquiry should be mailed to
joumon@cs.unm.edu.

o Perl
         -   starts with #!/usr/bin/per or with a proper path
         -   each statement ends with ;
         -   run with –d for debugging
         -   run with –w for warning
         -   comment with #
         -   case-sensitive

o Scalar Variables
       - start with $
       - use ‘my’
       ex)
       $var = 3;
       my $greet = “hello?”

         -   $_ : default variable for most operations
         -   @ARGV : arguments array
         -   @_ : argument array to functions and access with $_[index]
         -   use local for a local variable in a function

o Operators
       - +/-/*///%/**/./x/=/+=/-=/.=
       - single-quote and double-quote
       ex)
       “hello”.”world” --> “helloworld”
       “hello”x2       --> “hellohello”

         $var = 3;
         print “hi$var”; --> “hi3”
         print ‘hi$var’; --> “hi$var”

         - strings enclosed in single quotes are taken literally
         - strings enclosed in double quotes interpret variables or control
         characters ($var, n, r, etc.)

o Arrays
       - declare as @name=(elem1, elem2, ...);
       ex)
       my @family = (“Mary”, “John”)
       $family[1] --> “John”

         push(@family, “Chris”); --> push returns length
         my @wholefamily = (@family, “Bill”);
         push(@family, “Hellen”, “Jason”)
         push(@family, (“Hellen”, “Jason”));
push(@wholefamily, @family);

      $elem=pop(@family) --> pos returns an element

      $len=@family --> set length
      $str=”@family” --> set to string

      ($a, $b) = ($c, $d)
      ($a, $b) = @food; --> $a is the first element and $b is the rest
      (@a, $b) = @food; --> $b is undefined

      print @food;
      print “@food”;
      print @food.””;

      - use $name[index] to index
      - index starts from zero
      - $#array returns index of last element of an array, i.e. n-1

o File Handling
       - use open(), close()
       ex)
       $file=”hello.txt”;
       open(INFO, $file);
       while(<INFO>) {...} # or @lines = <INFO>;
       close(INFO);

      - use <STDIN>,<STDOUT>,<STDERR>
      ex)
      open(INFO, $file);      # Open for input
      open(INFO, ">$file");   # Open for output
      open(INFO, ">>$file"); # Open for appending
      open(INFO, "<$file");   # Also open for input
      open(INFO, '-');        # Open standard input
      open(INFO, '>-');       # Open standard output

      - use print <INFO> ...

o Control Structures
       - foreach $var (@array) {...}
       - for(init; final; step) {...}
       - while (predicate) {...}
       - do {...} while/until (predicate);
       - comparison operators: ==/!=/eq/ne
       - logical operators: ||/&&/!
       - if (predicate) {...} elsif (predicate) {...} ... else {...}
       - if (predicate) {...}: if predicate is missing, then $_ is used

o Regex
       - use =~ for pattern matching
       - use !~ for non-matching
       ex)
       $str = “hello world”
$a =~ /hel/ --> true
      $b !~ /hel/ --> false
      - if we assign to $_, then we could omit $_
      ex)
      $_ =”hello”
      if (/hel/) {...}
      - substitution: s/source/target/
      - use g for global substitution and use i for ignore-case
      ex)
      $var =~ s/long/LONG/
      s/long/LONG/      # $_ keeps the result
      - use $1, $2, ..., $9 to remember
      ex)
       s/^(.)(.*)(.)$/321/
      - use $`, $&, $’ to remember before, during, and after matching
      ex)
       $_ = "Lord Whopper of Fibbing";
       /pp/;
       $` eq "Lord Wo"; # true
       $& eq "pp";      # true
       $' eq "er of Fibbing"; #true

       $search = "the";
       s/$search/xxx/g;
       - tr function allows character by character translation
       ex)
       $sentence =~ tr/abc/edf/
       $count = ($sentence =~ tr/*/*/); # count
       tr/a-z/A-Z/;   # range

o More Regex
        -.      #   Any single character except a newline
        - ^     #   The beginning of the line or string
        - $     #   The end of the line or string
        - *     #   Zero or more of the last character
        - +     #   One or more of the last character
        -?      #   Zero or one of the last character

       -   [qjk]         #   Either q or j or k
       -   [^qjk]        #   Neither q nor j nor k
       -   [a-z]         #   Anything from a to z inclusive
       -   [^a-z]        #   No lower case letters
       -   [a-zA-Z]      #   Any letter
       -   [a-z]+        #   Any non-zero sequence of lower case letters
       -   jelly|cream   #   Either jelly or cream
       -   (eg|le)gs     #   Either eggs or legs
       -   (da)+         #   Either da or dada or dadada or...
       -   n            #   A newline
       -   t            #   A tab
       -   w            #   Any alphanumeric (word) character.
                         #   The same as [a-zA-Z0-9_]
       - W              #   Any non-word character.
                         #   The same as [^a-zA-Z0-9_]
- d            #   Any digit. The same as [0-9]
       - D            #   Any non-digit. The same as [^0-9]
       - s            #   Any whitespace character: space,
                       #   tab, newline, etc
       -   S          #   Any non-whitespace character
       -   b          #   A word boundary, outside [] only
       -   B          #   No word boundary
       -   |          #   Vertical bar
       -   [          #   An open square bracket
       -   )          #   A closing parenthesis
       -   *          #   An asterisk
       -   ^          #   A carat symbol
       -   /          #   A slash
       -             #   A backslash

       - {n} : match exactly n repetitions of the previous element
       - {n,} : match at least n repetitions
       - {n,m} : match at least n but no more than m repetitions

o Miscellaneous Functions
       - chomp()/chop()/split()/shift()/unshift()

o Functions
       - sub FUNC {...}
       - parameters in @_
       - the result of the last thing is returned

Más contenido relacionado

La actualidad más candente

Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressionsplarsen67
 
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
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP ArraysAhmed Swilam
 
Perl names values and variables
Perl names values and variablesPerl names values and variables
Perl names values and variablessana mateen
 

La actualidad más candente (11)

Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Dades i operadors
Dades i operadorsDades i operadors
Dades i operadors
 
tutorial7
tutorial7tutorial7
tutorial7
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Perl names values and variables
Perl names values and variablesPerl names values and variables
Perl names values and variables
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 

Destacado

1. hand out
1. hand out1. hand out
1. hand outshammasm
 
faiq ahmed nizami CV
faiq ahmed nizami CVfaiq ahmed nizami CV
faiq ahmed nizami CVFaiq Nizami
 
Introduction to Fodesco_2015_linkedin
Introduction to Fodesco_2015_linkedinIntroduction to Fodesco_2015_linkedin
Introduction to Fodesco_2015_linkedinZoltan Toth
 
Introduction to MS project
Introduction to MS projectIntroduction to MS project
Introduction to MS projectSamir Paralikar
 
Raju major n minor connectors/dental courses
Raju major n minor connectors/dental coursesRaju major n minor connectors/dental courses
Raju major n minor connectors/dental coursesIndian dental academy
 
The Güçlükonak Massacre
The Güçlükonak MassacreThe Güçlükonak Massacre
The Güçlükonak MassacreJohn Lubbock
 

Destacado (11)

1. hand out
1. hand out1. hand out
1. hand out
 
faiq ahmed nizami CV
faiq ahmed nizami CVfaiq ahmed nizami CV
faiq ahmed nizami CV
 
Introduction to Fodesco_2015_linkedin
Introduction to Fodesco_2015_linkedinIntroduction to Fodesco_2015_linkedin
Introduction to Fodesco_2015_linkedin
 
FinalEpagoge draft5
FinalEpagoge draft5FinalEpagoge draft5
FinalEpagoge draft5
 
Ergonomia app Esselunga
Ergonomia app EsselungaErgonomia app Esselunga
Ergonomia app Esselunga
 
Introduction to MS project
Introduction to MS projectIntroduction to MS project
Introduction to MS project
 
Raju major n minor connectors/dental courses
Raju major n minor connectors/dental coursesRaju major n minor connectors/dental courses
Raju major n minor connectors/dental courses
 
Аппарат для производства круассанов, модель CROYMAT 3000 – 6000 – 10000 - 120...
Аппарат для производства круассанов, модель CROYMAT 3000 – 6000 – 10000 - 120...Аппарат для производства круассанов, модель CROYMAT 3000 – 6000 – 10000 - 120...
Аппарат для производства круассанов, модель CROYMAT 3000 – 6000 – 10000 - 120...
 
Пленочно-контактная клавиатура управления CS03 для тестомесителя DOISNA (#27)
Пленочно-контактная клавиатура управления CS03 для тестомесителя DOISNA (#27)Пленочно-контактная клавиатура управления CS03 для тестомесителя DOISNA (#27)
Пленочно-контактная клавиатура управления CS03 для тестомесителя DOISNA (#27)
 
Газовая печь с вращающейся платформой RotorBake T11 на 18 противней (#4)
Газовая печь с вращающейся платформой RotorBake T11 на 18 противней (#4)Газовая печь с вращающейся платформой RotorBake T11 на 18 противней (#4)
Газовая печь с вращающейся платформой RotorBake T11 на 18 противней (#4)
 
The Güçlükonak Massacre
The Güçlükonak MassacreThe Güçlükonak Massacre
The Güçlükonak Massacre
 

Similar a perl-pocket

Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Lecture 23
Lecture 23Lecture 23
Lecture 23rhshriva
 
Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersGil Megidish
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl styleBo Hua Yang
 
Scripting3
Scripting3Scripting3
Scripting3Nao Dara
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perltinypigdotcom
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 
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
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressionsplarsen67
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashessana mateen
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 

Similar a perl-pocket (20)

Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Perl intro
Perl introPerl intro
Perl intro
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
tutorial7
tutorial7tutorial7
tutorial7
 
Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmers
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Scripting3
Scripting3Scripting3
Scripting3
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Introduction to perl_lists
Introduction to perl_listsIntroduction to perl_lists
Introduction to perl_lists
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
 
wget.pl
wget.plwget.pl
wget.pl
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashes
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 

Más de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Más de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Último

Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 

Último (20)

Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 

perl-pocket

  • 1. A Brief Pocket Reference for Perl Programming This pocket reference was created to help the author to refresh Perl, presumably aiming at an intermediate programmer or advanced. This pocket reference is mainly based on several anonymous resources found on the Internet. It’s free to distribute/modify. Any inquiry should be mailed to joumon@cs.unm.edu. o Perl - starts with #!/usr/bin/per or with a proper path - each statement ends with ; - run with –d for debugging - run with –w for warning - comment with # - case-sensitive o Scalar Variables - start with $ - use ‘my’ ex) $var = 3; my $greet = “hello?” - $_ : default variable for most operations - @ARGV : arguments array - @_ : argument array to functions and access with $_[index] - use local for a local variable in a function o Operators - +/-/*///%/**/./x/=/+=/-=/.= - single-quote and double-quote ex) “hello”.”world” --> “helloworld” “hello”x2 --> “hellohello” $var = 3; print “hi$var”; --> “hi3” print ‘hi$var’; --> “hi$var” - strings enclosed in single quotes are taken literally - strings enclosed in double quotes interpret variables or control characters ($var, n, r, etc.) o Arrays - declare as @name=(elem1, elem2, ...); ex) my @family = (“Mary”, “John”) $family[1] --> “John” push(@family, “Chris”); --> push returns length my @wholefamily = (@family, “Bill”); push(@family, “Hellen”, “Jason”) push(@family, (“Hellen”, “Jason”));
  • 2. push(@wholefamily, @family); $elem=pop(@family) --> pos returns an element $len=@family --> set length $str=”@family” --> set to string ($a, $b) = ($c, $d) ($a, $b) = @food; --> $a is the first element and $b is the rest (@a, $b) = @food; --> $b is undefined print @food; print “@food”; print @food.””; - use $name[index] to index - index starts from zero - $#array returns index of last element of an array, i.e. n-1 o File Handling - use open(), close() ex) $file=”hello.txt”; open(INFO, $file); while(<INFO>) {...} # or @lines = <INFO>; close(INFO); - use <STDIN>,<STDOUT>,<STDERR> ex) open(INFO, $file); # Open for input open(INFO, ">$file"); # Open for output open(INFO, ">>$file"); # Open for appending open(INFO, "<$file"); # Also open for input open(INFO, '-'); # Open standard input open(INFO, '>-'); # Open standard output - use print <INFO> ... o Control Structures - foreach $var (@array) {...} - for(init; final; step) {...} - while (predicate) {...} - do {...} while/until (predicate); - comparison operators: ==/!=/eq/ne - logical operators: ||/&&/! - if (predicate) {...} elsif (predicate) {...} ... else {...} - if (predicate) {...}: if predicate is missing, then $_ is used o Regex - use =~ for pattern matching - use !~ for non-matching ex) $str = “hello world”
  • 3. $a =~ /hel/ --> true $b !~ /hel/ --> false - if we assign to $_, then we could omit $_ ex) $_ =”hello” if (/hel/) {...} - substitution: s/source/target/ - use g for global substitution and use i for ignore-case ex) $var =~ s/long/LONG/ s/long/LONG/ # $_ keeps the result - use $1, $2, ..., $9 to remember ex) s/^(.)(.*)(.)$/321/ - use $`, $&, $’ to remember before, during, and after matching ex) $_ = "Lord Whopper of Fibbing"; /pp/; $` eq "Lord Wo"; # true $& eq "pp"; # true $' eq "er of Fibbing"; #true $search = "the"; s/$search/xxx/g; - tr function allows character by character translation ex) $sentence =~ tr/abc/edf/ $count = ($sentence =~ tr/*/*/); # count tr/a-z/A-Z/; # range o More Regex -. # Any single character except a newline - ^ # The beginning of the line or string - $ # The end of the line or string - * # Zero or more of the last character - + # One or more of the last character -? # Zero or one of the last character - [qjk] # Either q or j or k - [^qjk] # Neither q nor j nor k - [a-z] # Anything from a to z inclusive - [^a-z] # No lower case letters - [a-zA-Z] # Any letter - [a-z]+ # Any non-zero sequence of lower case letters - jelly|cream # Either jelly or cream - (eg|le)gs # Either eggs or legs - (da)+ # Either da or dada or dadada or... - n # A newline - t # A tab - w # Any alphanumeric (word) character. # The same as [a-zA-Z0-9_] - W # Any non-word character. # The same as [^a-zA-Z0-9_]
  • 4. - d # Any digit. The same as [0-9] - D # Any non-digit. The same as [^0-9] - s # Any whitespace character: space, # tab, newline, etc - S # Any non-whitespace character - b # A word boundary, outside [] only - B # No word boundary - | # Vertical bar - [ # An open square bracket - ) # A closing parenthesis - * # An asterisk - ^ # A carat symbol - / # A slash - # A backslash - {n} : match exactly n repetitions of the previous element - {n,} : match at least n repetitions - {n,m} : match at least n but no more than m repetitions o Miscellaneous Functions - chomp()/chop()/split()/shift()/unshift() o Functions - sub FUNC {...} - parameters in @_ - the result of the last thing is returned