SlideShare une entreprise Scribd logo
1  sur  4
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

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

En vedette

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
 

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

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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