SlideShare a Scribd company logo
Learn Perl at
AMC Square Learning
Perl
• "Practical Extraction and Reporting Language"
• written by Larry Wall and first released in 1987
• Perl has become a very large system of modules
• name came first, then the acronym
• designed to be a "glue" language to fill the gap
between compiled programs (output of "gcc", etc.)
and scripting languages
• "Perl is a language for easily manipulating text, files
and processes": originally aimed at systems
administrators and developers
What is Perl?
Perl is a High-level Scripting language
Faster than sh or csh, slower than C
No need for sed, awk, head, wc, tr, …
Compiles at run-time
Available for Unix, PC, Mac
Best Regular Expressions on Earth
Executing Perl scripts
•"bang path" convention for scripts:
• can invoke Perl at the command line, or
• add #!/public/bin/perl at the beginning of the script
• exact value of path depends upon your platform (use "which perl"
to find the path)
•one execution method:
% perl
print "Hello, World!n";
CTRL-D
Hello, World!
•preferred method: set bang-path and ensure
executable flag is set on the script file
Perl Basics
Comment lines begin with: #
File Naming Scheme
• filename.pl (programs)
• filename.pm (modules)
Example prog: print “Hello, World!n”;
Statements must end with semicolon
$a = 0;
Should call exit() function when finished
Exit value of zero means success
exit (0); # successful
Exit value non-zero means failure
exit (2); # failure
Data Types
Integer
• 25 750000 1_000_000_000
• 8#100 16#FFFF0000
Floating Point
• 1.25 50.0 6.02e23 -1.6E-8
String
• ‘hi there’ “hi there, $name” qq(tin can)
• print “Text Utility, version $vern”;
Boolean
0 0.0 “” "0" represent
False
all other values represent
True
Variable Types
Scalar
• $num = 14;
• $fullname = “John H. Smith”;
• Variable Names are Case Sensitive
• Underlines Allowed: $Program_Version = 1.0;
Scalars
• usage of scalars:
print ("pi is equal to: $pin");
print "pi is still equal to: ", $pi, "n";
$c = $a + $b
• important! A scalar variable can be "used" before it is first
assigned a value
• result depends on context
• either a blank string ("") or a zero (0)
• this is a source of very subtle bugs
• if variable name is mispelled — what should be the result?
• do not let yourself get caught by this – use the "-w" flag in
the bang path:
#!/public/bin/perl -w
Operators
Math
• The usual suspects: + - * / %
 $total = $subtotal * (1 + $tax / 100.0);
• Exponentiation: **
 $cube = $value ** 3;
 $cuberoot = $value ** (1.0/3);
• Bit-level Operations
 left-shift: << $val = $bits << 1;
 right-shift: >> $val = $bits >> 8;
Assignments
As usual: = += -= *= /= **= <<= >>=
$value *= 5;
$longword <<= 16;
Increment: ++
$counter++ ++
$counter
Decrement: --
$num_tries-- --$num_tries
Arithmetic
• Perl operators are the same as in C and Java
• these are only good for numbers
• but beware:
$b = "3" + "5";
print $b, "n"; # prints the number 8
• if a string can be interpreted as a number given arithmetic
operators, it will be
• what is the value of $b?:
$b = "3" + "five" + 6?
• Perl semantics can be tricky to completely understand
Conditionals
Numeric string
Equal: == eq
Less/Greater Than: < > lt gt
Less/Greater or equal: <= >=le ge
Zero and empty-string means False
All other values equate to True
Comparison: <=>
cmp
Results in a value of -1, 0, or 1
Logical Not: !
if (! $done) {
print “keep going”;
}
Control Structures
“if” statement - second style
• statement if condition;
 print “$index is $index” if $DEBUG;
• Single statements only
• Simple expressions only
•“unless” is a reverse “if”
• statement unless condition;
 print “millenium is here!” unless $year < 2000;
Subroutines (Functions)
Calling a Subroutine
• &subname; # no args, no return value
• &subname (args);
• retval = &subname (args);
• The “&” is optional so long as…
 subname is not a reserved word
 subroutine was defined before being called
Passing Arguments
Passes the value
Lists are expanded
@a = (5,10,15);
@b = (20,25);
&mysub(@a,@b);
this passes five arguments:
5,10,15,20,25
mysub can receive them as 5
scalars, or one array
Command Line Args
$0 = program name
@ARGV array of arguments to program
zero-based index (default for all arrays)
Example
• yourprog -a somefile
 $0 is “yourprog”
 $ARGV[0] is “-a”
 $ARGV[1] is “somefile”
Basic File I/O
Reading a File
• open (FILEHANDLE, “$filename”) || die  “open of $filename failed: $!”;
while (<FILEHANDLE>) {
chomp $_; # or just: chomp;
print “$_n”;
}
close FILEHANDLE;
Writing a File
open (FILEHANDLE, “>$filename”) || die 
“open of $filename failed: $!”;
while (@data) {
print FILEHANDLE “$_n”;
# note,
no comma!
}
close FILEHANDLE;
Debugging in Perl
-w option is great!
• #!/bin/perl -w
• tells you about…
 misused variables
 using uninitialized data/varables
 identifiers that are used only once
 and more
Debug mode: perl -d filename [args]
Display Commands
h
Extended help
h h
Abbreviated help
l (lowercase-L) list lines of code
l sub list subroutine sub
l 5 list line 5
l 3-6 list lines 3 through 6
inclusive
l list next
window of lines
Thank you

More Related Content

What's hot (20)

PPT
Php Chapter 2 3 Training
Chris Chubb
 
PDF
Elixir and Phoenix for Rubyists
Brooklyn Zelenka
 
PPTX
PHP Basics
Muthuganesh S
 
PPTX
Introduction in php
Bozhidar Boshnakov
 
PPTX
Arrays &amp; functions in php
Ashish Chamoli
 
PDF
PHP Unit 3 functions_in_php_2
Kumar
 
PPTX
Bioinformatics p4-io v2013-wim_vancriekinge
Prof. Wim Van Criekinge
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPTX
php basics
Anmol Paul
 
KEY
PHP Underground Session 1: The Basics
Robin Hawkes
 
PPT
Functions in php
Mudasir Syed
 
PDF
Introduction to php
KIRAN KUMAR SILIVERI
 
PPTX
Php basics
Jamshid Hashimi
 
PPSX
PHP Comprehensive Overview
Mohamed Loey
 
PPTX
Introduction in php part 2
Bozhidar Boshnakov
 
PPT
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PPT
Class 2 - Introduction to PHP
Ahmed Swilam
 
PPT
Introduction to php
sagaroceanic11
 
PPT
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
Php Chapter 2 3 Training
Chris Chubb
 
Elixir and Phoenix for Rubyists
Brooklyn Zelenka
 
PHP Basics
Muthuganesh S
 
Introduction in php
Bozhidar Boshnakov
 
Arrays &amp; functions in php
Ashish Chamoli
 
PHP Unit 3 functions_in_php_2
Kumar
 
Bioinformatics p4-io v2013-wim_vancriekinge
Prof. Wim Van Criekinge
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
php basics
Anmol Paul
 
PHP Underground Session 1: The Basics
Robin Hawkes
 
Functions in php
Mudasir Syed
 
Introduction to php
KIRAN KUMAR SILIVERI
 
Php basics
Jamshid Hashimi
 
PHP Comprehensive Overview
Mohamed Loey
 
Introduction in php part 2
Bozhidar Boshnakov
 
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
Class 2 - Introduction to PHP
Ahmed Swilam
 
Introduction to php
sagaroceanic11
 
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 

Viewers also liked (14)

PPT
Pobyt 2010 - Fundamentalismus
benskala
 
PDF
คู่มือการใช้งานและการเขียนมีเดียวิกิ
Pasawoot Kai
 
PPTX
La innovacion
Carmina Munguia Melendez
 
DOCX
Reseña Las Alucinaciones
Daniela García
 
PPTX
Attacks of september 11 in usa
Roberto Jimenez
 
PDF
20141002-「專利師法」部分條文修正草案
R.O.C.Executive Yuan
 
PPTX
The sombrerón
Rr159123
 
PPTX
Interesting Facts Regarding Phone Psychic Medium Reading
kmslerma
 
PPTX
Potrebne informacije o tujih trgih in njihovi možni viri
Anamarija Škof
 
PDF
How to create the best possible eCommerce experience for your customers, usin...
Kumar Padmanabhan
 
PPTX
Adverb Clauses of Time
Maria José Carmelo Samaniego
 
PDF
WordPress Facilissimo: guida alla sicurezza
Flavius-Florin Harabor
 
PPTX
Emperador roma
Noemi Marcera
 
PPT
Augustus Caesar at ang PAX ROMANA
Noemi Marcera
 
Pobyt 2010 - Fundamentalismus
benskala
 
คู่มือการใช้งานและการเขียนมีเดียวิกิ
Pasawoot Kai
 
Reseña Las Alucinaciones
Daniela García
 
Attacks of september 11 in usa
Roberto Jimenez
 
20141002-「專利師法」部分條文修正草案
R.O.C.Executive Yuan
 
The sombrerón
Rr159123
 
Interesting Facts Regarding Phone Psychic Medium Reading
kmslerma
 
Potrebne informacije o tujih trgih in njihovi možni viri
Anamarija Škof
 
How to create the best possible eCommerce experience for your customers, usin...
Kumar Padmanabhan
 
Adverb Clauses of Time
Maria José Carmelo Samaniego
 
WordPress Facilissimo: guida alla sicurezza
Flavius-Florin Harabor
 
Emperador roma
Noemi Marcera
 
Augustus Caesar at ang PAX ROMANA
Noemi Marcera
 
Ad

Similar to Learn perl in amc square learning (20)

PPT
Introduction to Perl
NBACriteria2SICET
 
PPTX
Perl slid
pacatarpit
 
PPTX
Perl courseparti
ernlow
 
DOCX
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
PPT
Perl tutorial
Manav Prasad
 
PPT
PERL.ppt
Farmood Alam
 
PPT
Introduction to perl scripting______.ppt
nalinisamineni
 
PPT
Perl Basics with Examples
Nithin Kumar Singani
 
PDF
perltut
tutorialsruby
 
PDF
perltut
tutorialsruby
 
PPT
Perl Programming_Guide_Document_Refr.ppt
ssuserf4000e1
 
PPT
Perl training-in-navi mumbai
vibrantuser
 
PDF
newperl5
tutorialsruby
 
PDF
newperl5
tutorialsruby
 
PPTX
Intro to Perl
primeteacher32
 
ODP
Beginning Perl
Dave Cross
 
PPTX
Bioinformatics p1-perl-introduction v2013
Prof. Wim Van Criekinge
 
PDF
First steps in PERL
Brahma Killampalli
 
PPT
Introduction to perl_ a scripting language
Vamshi Santhapuri
 
ODP
Introduction to Perl
Dave Cross
 
Introduction to Perl
NBACriteria2SICET
 
Perl slid
pacatarpit
 
Perl courseparti
ernlow
 
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
Perl tutorial
Manav Prasad
 
PERL.ppt
Farmood Alam
 
Introduction to perl scripting______.ppt
nalinisamineni
 
Perl Basics with Examples
Nithin Kumar Singani
 
perltut
tutorialsruby
 
perltut
tutorialsruby
 
Perl Programming_Guide_Document_Refr.ppt
ssuserf4000e1
 
Perl training-in-navi mumbai
vibrantuser
 
newperl5
tutorialsruby
 
newperl5
tutorialsruby
 
Intro to Perl
primeteacher32
 
Beginning Perl
Dave Cross
 
Bioinformatics p1-perl-introduction v2013
Prof. Wim Van Criekinge
 
First steps in PERL
Brahma Killampalli
 
Introduction to perl_ a scripting language
Vamshi Santhapuri
 
Introduction to Perl
Dave Cross
 
Ad

More from ASIT Education (20)

PPTX
COMMON PROBLEMS FACING WITH TABLETS
ASIT Education
 
PPTX
Simple hardware problems facing in pc's
ASIT Education
 
DOCX
Amc square IT services
ASIT Education
 
PPT
learn JAVA at ASIT with a placement assistance.
ASIT Education
 
PPT
Learn my sql at amc square learning
ASIT Education
 
PPT
Learn joomla at amc square learning
ASIT Education
 
PPT
learn ANDROID at AMC Square Learning
ASIT Education
 
PPT
Learn spring at amc square learning
ASIT Education
 
PPT
Learn cpp at amc square learning
ASIT Education
 
PPT
Learn c sharp at amc square learning
ASIT Education
 
PPT
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
PPT
learn sharepoint at AMC Square learning
ASIT Education
 
PPT
Introduction to software testing
ASIT Education
 
PPTX
C programmimng basic.ppt
ASIT Education
 
PPT
Ruby programming introduction
ASIT Education
 
PPT
Introduction to vm ware
ASIT Education
 
PPT
Introduction to software testing
ASIT Education
 
PPT
Introduction to phython programming
ASIT Education
 
PPT
Introduction to java programming
ASIT Education
 
PPTX
Introduction to internet
ASIT Education
 
COMMON PROBLEMS FACING WITH TABLETS
ASIT Education
 
Simple hardware problems facing in pc's
ASIT Education
 
Amc square IT services
ASIT Education
 
learn JAVA at ASIT with a placement assistance.
ASIT Education
 
Learn my sql at amc square learning
ASIT Education
 
Learn joomla at amc square learning
ASIT Education
 
learn ANDROID at AMC Square Learning
ASIT Education
 
Learn spring at amc square learning
ASIT Education
 
Learn cpp at amc square learning
ASIT Education
 
Learn c sharp at amc square learning
ASIT Education
 
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
learn sharepoint at AMC Square learning
ASIT Education
 
Introduction to software testing
ASIT Education
 
C programmimng basic.ppt
ASIT Education
 
Ruby programming introduction
ASIT Education
 
Introduction to vm ware
ASIT Education
 
Introduction to software testing
ASIT Education
 
Introduction to phython programming
ASIT Education
 
Introduction to java programming
ASIT Education
 
Introduction to internet
ASIT Education
 

Recently uploaded (20)

PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Horarios de distribución de agua en julio
pegazohn1978
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 

Learn perl in amc square learning

  • 1. Learn Perl at AMC Square Learning
  • 2. Perl • "Practical Extraction and Reporting Language" • written by Larry Wall and first released in 1987 • Perl has become a very large system of modules • name came first, then the acronym • designed to be a "glue" language to fill the gap between compiled programs (output of "gcc", etc.) and scripting languages • "Perl is a language for easily manipulating text, files and processes": originally aimed at systems administrators and developers
  • 3. What is Perl? Perl is a High-level Scripting language Faster than sh or csh, slower than C No need for sed, awk, head, wc, tr, … Compiles at run-time Available for Unix, PC, Mac Best Regular Expressions on Earth
  • 4. Executing Perl scripts •"bang path" convention for scripts: • can invoke Perl at the command line, or • add #!/public/bin/perl at the beginning of the script • exact value of path depends upon your platform (use "which perl" to find the path) •one execution method: % perl print "Hello, World!n"; CTRL-D Hello, World! •preferred method: set bang-path and ensure executable flag is set on the script file
  • 5. Perl Basics Comment lines begin with: # File Naming Scheme • filename.pl (programs) • filename.pm (modules) Example prog: print “Hello, World!n”; Statements must end with semicolon $a = 0; Should call exit() function when finished Exit value of zero means success exit (0); # successful Exit value non-zero means failure exit (2); # failure
  • 6. Data Types Integer • 25 750000 1_000_000_000 • 8#100 16#FFFF0000 Floating Point • 1.25 50.0 6.02e23 -1.6E-8 String • ‘hi there’ “hi there, $name” qq(tin can) • print “Text Utility, version $vern”; Boolean 0 0.0 “” "0" represent False all other values represent True
  • 7. Variable Types Scalar • $num = 14; • $fullname = “John H. Smith”; • Variable Names are Case Sensitive • Underlines Allowed: $Program_Version = 1.0;
  • 8. Scalars • usage of scalars: print ("pi is equal to: $pin"); print "pi is still equal to: ", $pi, "n"; $c = $a + $b • important! A scalar variable can be "used" before it is first assigned a value • result depends on context • either a blank string ("") or a zero (0) • this is a source of very subtle bugs • if variable name is mispelled — what should be the result? • do not let yourself get caught by this – use the "-w" flag in the bang path: #!/public/bin/perl -w
  • 9. Operators Math • The usual suspects: + - * / %  $total = $subtotal * (1 + $tax / 100.0); • Exponentiation: **  $cube = $value ** 3;  $cuberoot = $value ** (1.0/3); • Bit-level Operations  left-shift: << $val = $bits << 1;  right-shift: >> $val = $bits >> 8; Assignments As usual: = += -= *= /= **= <<= >>= $value *= 5; $longword <<= 16; Increment: ++ $counter++ ++ $counter Decrement: -- $num_tries-- --$num_tries
  • 10. Arithmetic • Perl operators are the same as in C and Java • these are only good for numbers • but beware: $b = "3" + "5"; print $b, "n"; # prints the number 8 • if a string can be interpreted as a number given arithmetic operators, it will be • what is the value of $b?: $b = "3" + "five" + 6? • Perl semantics can be tricky to completely understand
  • 11. Conditionals Numeric string Equal: == eq Less/Greater Than: < > lt gt Less/Greater or equal: <= >=le ge Zero and empty-string means False All other values equate to True Comparison: <=> cmp Results in a value of -1, 0, or 1 Logical Not: ! if (! $done) { print “keep going”; }
  • 12. Control Structures “if” statement - second style • statement if condition;  print “$index is $index” if $DEBUG; • Single statements only • Simple expressions only •“unless” is a reverse “if” • statement unless condition;  print “millenium is here!” unless $year < 2000;
  • 13. Subroutines (Functions) Calling a Subroutine • &subname; # no args, no return value • &subname (args); • retval = &subname (args); • The “&” is optional so long as…  subname is not a reserved word  subroutine was defined before being called Passing Arguments Passes the value Lists are expanded @a = (5,10,15); @b = (20,25); &mysub(@a,@b); this passes five arguments: 5,10,15,20,25 mysub can receive them as 5 scalars, or one array
  • 14. Command Line Args $0 = program name @ARGV array of arguments to program zero-based index (default for all arrays) Example • yourprog -a somefile  $0 is “yourprog”  $ARGV[0] is “-a”  $ARGV[1] is “somefile”
  • 15. Basic File I/O Reading a File • open (FILEHANDLE, “$filename”) || die “open of $filename failed: $!”; while (<FILEHANDLE>) { chomp $_; # or just: chomp; print “$_n”; } close FILEHANDLE; Writing a File open (FILEHANDLE, “>$filename”) || die “open of $filename failed: $!”; while (@data) { print FILEHANDLE “$_n”; # note, no comma! } close FILEHANDLE;
  • 16. Debugging in Perl -w option is great! • #!/bin/perl -w • tells you about…  misused variables  using uninitialized data/varables  identifiers that are used only once  and more Debug mode: perl -d filename [args] Display Commands h Extended help h h Abbreviated help l (lowercase-L) list lines of code l sub list subroutine sub l 5 list line 5 l 3-6 list lines 3 through 6 inclusive l list next window of lines