SlideShare a Scribd company logo
1 of 17
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)

Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for Rubyists
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekinge
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
php basics
php basicsphp basics
php basics
 
PHP Underground Session 1: The Basics
PHP Underground Session 1: The BasicsPHP Underground Session 1: The Basics
PHP Underground Session 1: The Basics
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Php basics
Php basicsPhp basics
Php basics
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 

Viewers also liked

Pobyt 2010 - Fundamentalismus
Pobyt 2010 - FundamentalismusPobyt 2010 - Fundamentalismus
Pobyt 2010 - Fundamentalismusbenskala
 
คู่มือการใช้งานและการเขียนมีเดียวิกิ
คู่มือการใช้งานและการเขียนมีเดียวิกิคู่มือการใช้งานและการเขียนมีเดียวิกิ
คู่มือการใช้งานและการเขียนมีเดียวิกิPasawoot Kai
 
Reseña Las Alucinaciones
Reseña Las Alucinaciones Reseña Las Alucinaciones
Reseña Las Alucinaciones Daniela García
 
Attacks of september 11 in usa
Attacks of september 11 in usa Attacks of september 11 in usa
Attacks of september 11 in usa Roberto Jimenez
 
20141002-「專利師法」部分條文修正草案
20141002-「專利師法」部分條文修正草案20141002-「專利師法」部分條文修正草案
20141002-「專利師法」部分條文修正草案R.O.C.Executive Yuan
 
The sombrerón
The sombrerónThe sombrerón
The sombrerónRr159123
 
Interesting Facts Regarding Phone Psychic Medium Reading
Interesting Facts Regarding Phone Psychic Medium ReadingInteresting Facts Regarding Phone Psychic Medium Reading
Interesting Facts Regarding Phone Psychic Medium Readingkmslerma
 
Potrebne informacije o tujih trgih in njihovi možni viri
Potrebne informacije o tujih trgih in njihovi možni viriPotrebne informacije o tujih trgih in njihovi možni viri
Potrebne informacije o tujih trgih in njihovi možni viriAnamarija Škof
 
How to create the best possible eCommerce experience for your customers, usin...
How to create the best possible eCommerce experience for your customers, usin...How to create the best possible eCommerce experience for your customers, usin...
How to create the best possible eCommerce experience for your customers, usin...Kumar Padmanabhan
 
WordPress Facilissimo: guida alla sicurezza
WordPress Facilissimo: guida alla sicurezzaWordPress Facilissimo: guida alla sicurezza
WordPress Facilissimo: guida alla sicurezzaFlavius-Florin Harabor
 
Augustus Caesar at ang PAX ROMANA
Augustus Caesar at ang PAX ROMANAAugustus Caesar at ang PAX ROMANA
Augustus Caesar at ang PAX ROMANANoemi Marcera
 

Viewers also liked (14)

Pobyt 2010 - Fundamentalismus
Pobyt 2010 - FundamentalismusPobyt 2010 - Fundamentalismus
Pobyt 2010 - Fundamentalismus
 
คู่มือการใช้งานและการเขียนมีเดียวิกิ
คู่มือการใช้งานและการเขียนมีเดียวิกิคู่มือการใช้งานและการเขียนมีเดียวิกิ
คู่มือการใช้งานและการเขียนมีเดียวิกิ
 
La innovacion
La innovacionLa innovacion
La innovacion
 
Reseña Las Alucinaciones
Reseña Las Alucinaciones Reseña Las Alucinaciones
Reseña Las Alucinaciones
 
Attacks of september 11 in usa
Attacks of september 11 in usa Attacks of september 11 in usa
Attacks of september 11 in usa
 
20141002-「專利師法」部分條文修正草案
20141002-「專利師法」部分條文修正草案20141002-「專利師法」部分條文修正草案
20141002-「專利師法」部分條文修正草案
 
The sombrerón
The sombrerónThe sombrerón
The sombrerón
 
Interesting Facts Regarding Phone Psychic Medium Reading
Interesting Facts Regarding Phone Psychic Medium ReadingInteresting Facts Regarding Phone Psychic Medium Reading
Interesting Facts Regarding Phone Psychic Medium Reading
 
Potrebne informacije o tujih trgih in njihovi možni viri
Potrebne informacije o tujih trgih in njihovi možni viriPotrebne informacije o tujih trgih in njihovi možni viri
Potrebne informacije o tujih trgih in njihovi možni viri
 
How to create the best possible eCommerce experience for your customers, usin...
How to create the best possible eCommerce experience for your customers, usin...How to create the best possible eCommerce experience for your customers, usin...
How to create the best possible eCommerce experience for your customers, usin...
 
Adverb Clauses of Time
Adverb Clauses of Time Adverb Clauses of Time
Adverb Clauses of Time
 
WordPress Facilissimo: guida alla sicurezza
WordPress Facilissimo: guida alla sicurezzaWordPress Facilissimo: guida alla sicurezza
WordPress Facilissimo: guida alla sicurezza
 
Emperador roma
Emperador romaEmperador roma
Emperador roma
 
Augustus Caesar at ang PAX ROMANA
Augustus Caesar at ang PAX ROMANAAugustus Caesar at ang PAX ROMANA
Augustus Caesar at ang PAX ROMANA
 

Similar to Learn perl in amc square learning

Similar to Learn perl in amc square learning (20)

Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbai
 
Intro to Perl
Intro to PerlIntro to Perl
Intro to Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Syntax
SyntaxSyntax
Syntax
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
php
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
05php
05php05php
05php
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Perl bhargav
Perl bhargavPerl bhargav
Perl bhargav
 

More from ASIT Education

COMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETSCOMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETSASIT Education
 
Simple hardware problems facing in pc's
Simple hardware problems facing in pc'sSimple hardware problems facing in pc's
Simple hardware problems facing in pc'sASIT Education
 
Amc square IT services
Amc square IT servicesAmc square IT services
Amc square IT servicesASIT Education
 
learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.ASIT Education
 
Learn my sql at amc square learning
Learn my sql at amc square learningLearn my sql at amc square learning
Learn my sql at amc square learningASIT Education
 
Learn joomla at amc square learning
Learn joomla at amc square learningLearn joomla at amc square learning
Learn joomla at amc square learningASIT Education
 
learn ANDROID at AMC Square Learning
learn ANDROID at AMC Square Learninglearn ANDROID at AMC Square Learning
learn ANDROID at AMC Square LearningASIT Education
 
Learn spring at amc square learning
Learn spring at amc square learningLearn spring at amc square learning
Learn spring at amc square learningASIT Education
 
Learn cpp at amc square learning
Learn cpp at amc square learningLearn cpp at amc square learning
Learn cpp at amc square learningASIT Education
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learningASIT Education
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningASIT Education
 
learn sharepoint at AMC Square learning
learn sharepoint at AMC Square learninglearn sharepoint at AMC Square learning
learn sharepoint at AMC Square learningASIT Education
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testingASIT Education
 
C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.pptASIT Education
 
Ruby programming introduction
Ruby programming introductionRuby programming introduction
Ruby programming introductionASIT Education
 
Introduction to vm ware
Introduction to vm wareIntroduction to vm ware
Introduction to vm wareASIT Education
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testingASIT Education
 
Introduction to phython programming
Introduction to phython programmingIntroduction to phython programming
Introduction to phython programmingASIT Education
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programmingASIT Education
 
Introduction to internet
Introduction to internetIntroduction to internet
Introduction to internetASIT Education
 

More from ASIT Education (20)

COMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETSCOMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETS
 
Simple hardware problems facing in pc's
Simple hardware problems facing in pc'sSimple hardware problems facing in pc's
Simple hardware problems facing in pc's
 
Amc square IT services
Amc square IT servicesAmc square IT services
Amc square IT services
 
learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.
 
Learn my sql at amc square learning
Learn my sql at amc square learningLearn my sql at amc square learning
Learn my sql at amc square learning
 
Learn joomla at amc square learning
Learn joomla at amc square learningLearn joomla at amc square learning
Learn joomla at amc square learning
 
learn ANDROID at AMC Square Learning
learn ANDROID at AMC Square Learninglearn ANDROID at AMC Square Learning
learn ANDROID at AMC Square Learning
 
Learn spring at amc square learning
Learn spring at amc square learningLearn spring at amc square learning
Learn spring at amc square learning
 
Learn cpp at amc square learning
Learn cpp at amc square learningLearn cpp at amc square learning
Learn cpp at amc square learning
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learning
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
 
learn sharepoint at AMC Square learning
learn sharepoint at AMC Square learninglearn sharepoint at AMC Square learning
learn sharepoint at AMC Square learning
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.ppt
 
Ruby programming introduction
Ruby programming introductionRuby programming introduction
Ruby programming introduction
 
Introduction to vm ware
Introduction to vm wareIntroduction to vm ware
Introduction to vm ware
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
Introduction to phython programming
Introduction to phython programmingIntroduction to phython programming
Introduction to phython programming
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
Introduction to internet
Introduction to internetIntroduction to internet
Introduction to internet
 

Recently uploaded

Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

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