SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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 ...
 

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