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

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Dernier (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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?
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

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