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)

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
phpphp
php
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of 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

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...sanghavirahi2
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online PresentationGDSCYCCE
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 

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