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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

The NEW Local Search Strategies
The NEW Local Search StrategiesThe NEW Local Search Strategies
The NEW Local Search Strategiesshuey03
 
Manual del usuario Satloc bantam
Manual del usuario Satloc bantamManual del usuario Satloc bantam
Manual del usuario Satloc bantamJeferson Gomez
 
Why Doesn't My Website Show Up In The Search Engines?
Why Doesn't My Website Show Up In The Search Engines?Why Doesn't My Website Show Up In The Search Engines?
Why Doesn't My Website Show Up In The Search Engines?shuey03
 
Robert Rabiah - articles
Robert Rabiah - articlesRobert Rabiah - articles
Robert Rabiah - articlesROBERT RABIAH
 
Aspectos principales al escribir un ensayo word
Aspectos principales al escribir un ensayo wordAspectos principales al escribir un ensayo word
Aspectos principales al escribir un ensayo wordluis henrry gusqui cayo
 
Evaluacion para el curso. sopa de-letras
Evaluacion para el curso. sopa de-letrasEvaluacion para el curso. sopa de-letras
Evaluacion para el curso. sopa de-letrasluis henrry gusqui cayo
 
encuesta sobre sistema de calificaciones utc
encuesta sobre sistema de calificaciones utcencuesta sobre sistema de calificaciones utc
encuesta sobre sistema de calificaciones utcRoNald Paul
 
RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...
RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...
RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...Indian dental academy
 

Viewers also liked (18)

The NEW Local Search Strategies
The NEW Local Search StrategiesThe NEW Local Search Strategies
The NEW Local Search Strategies
 
Hendrickx06
Hendrickx06Hendrickx06
Hendrickx06
 
Manual del usuario Satloc bantam
Manual del usuario Satloc bantamManual del usuario Satloc bantam
Manual del usuario Satloc bantam
 
Why Doesn't My Website Show Up In The Search Engines?
Why Doesn't My Website Show Up In The Search Engines?Why Doesn't My Website Show Up In The Search Engines?
Why Doesn't My Website Show Up In The Search Engines?
 
Robert Rabiah - articles
Robert Rabiah - articlesRobert Rabiah - articles
Robert Rabiah - articles
 
Expresion oral word
Expresion oral  wordExpresion oral  word
Expresion oral word
 
Equipes
EquipesEquipes
Equipes
 
Cuadro de-participacion word
Cuadro de-participacion  wordCuadro de-participacion  word
Cuadro de-participacion word
 
Sopa de letras
Sopa de letrasSopa de letras
Sopa de letras
 
Word debate
Word debateWord debate
Word debate
 
Aspectos principales al escribir un ensayo word
Aspectos principales al escribir un ensayo wordAspectos principales al escribir un ensayo word
Aspectos principales al escribir un ensayo word
 
Restas
Restas Restas
Restas
 
Sopa de letras
Sopa de letrasSopa de letras
Sopa de letras
 
Evaluacion para el curso. sopa de-letras
Evaluacion para el curso. sopa de-letrasEvaluacion para el curso. sopa de-letras
Evaluacion para el curso. sopa de-letras
 
encuesta sobre sistema de calificaciones utc
encuesta sobre sistema de calificaciones utcencuesta sobre sistema de calificaciones utc
encuesta sobre sistema de calificaciones utc
 
A question of trust
A question of trustA question of trust
A question of trust
 
El portafolio word
El portafolio   wordEl portafolio   word
El portafolio word
 
RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...
RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...
RED CELL MEMBRANE: PAST, PRESENT, AND FUTURE / certified fixed orthodontic co...
 

Similar to 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 to 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
 

More from 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
 

More from 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
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

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