Introduction to Perl Part I By: Cdric Notredame (Adapted from
BT McInnes)
Slide 2
2 What is Perl? Perl is a Portable Scripting Language No
compiling is needed. Runs on Windows, UNIX, LINUX and cygwin Fast
and easy text processing capability Fast and easy file handling
capability Written by Larry Wall Perl is the language for getting
your job done. Too Slow For Number Crunching Ideal for
Prototyping
Slide 3
3 How to Access Perl To install at home Perl Comes by Default
on Linux, Cygwin, MacOSX www.perl.com Has rpm's for Linux
www.perl.com www.activestate.com Has binaries for Windows
www.activestate.com Latest Version is 5.8 To check if Perl is
working and the version number % perl -v
Slide 4
4 Resources For Perl Books: Learning Perl By Larry Wall
Published by O'Reilly Programming Perl By Larry Wall,Tom
Christiansen and Jon Orwant Published by O'Reilly Web Site
http://safari.oreilly.com Contains both Learning Perl and
Programming Perl in ebook form
Slide 5
5 Web Sources for Perl Web www.perl.com www.perldoc.com
www.perl.org www.perlmonks.org
Slide 6
6 The Basic Hello World Program which perl pico hello.pl
Program: #! /path/perl -w print Hello World!\n; Save this as
hello.pl Give it executable permissions chmod a+x hello.pl Run it
as follows:./hello.pl
Slide 7
7 Hello World Observations .pl extension is optional but is
commonly used The first line #!/usr/local/bin/perl tells UNIX where
to find Perl -w switches on warning : not required but a really
good idea
Slide 8
Variables and Their Content
Slide 9
9 Numerical Literals 6Integer 12.6Floating Point 1e10Scientific
Notation 6.4E-33Scientific Notation 4_348_348Underscores instead of
commas for long numbers
Slide 10
10 String Literals There is more than one way to do it! 'Just
don't create a file called -rf.' Beauty?\nWhat's that?\n Real
programmers can write assembly in any language. Quotes from Larry
Wall
Slide 11
11 Types of Variables Types of variables: Scalar variables :
$a, $b, $c Array variables : @array Hash variables : %hash File
handles : STDIN, STDOUT, STDERR Variables do not need to be
declared Variable type (int, char,...) is decided at run time $a =
5; # now an integer $a = perl; # now a string
Slide 12
12 Operators on Scalar Variables Numeric and Logic Operators
Typical : +, -, *, /, %, ++, --, +=, -=, *=, /=, ||, &&, !
ect Not typical: ** for exponentiation String Operators
Concatenation: . - similar to strcat $first_name = Larry;
$last_name = Wall; $full_name = $first_name. . $last_name;
Slide 13
13 Equality Operators for Strings Equality/ Inequality : eq and
ne $language = Perl; if ($language == Perl)...# Wrong! if
($language eq Perl)...#Correct Use eq / ne rather than == / != for
strings
Slide 14
14 Relational Operators for Strings Greater than Numeric :
>String : gt Greater than or equal to Numeric : >=String : ge
Less than Numeric :