Académique Documents
Professionnel Documents
Culture Documents
1387/09/23
Generic view
History Features Syntax Date objects Arrays Loops & conditional exprs Operators Subroutines Functions Regular Expressions I/O and file handles Applications And at the end.. refrences
2/25
History
SH
SED
C Perl
Lis p
AW K
Ruby
PHP
3/25
(perl)
5.10.0 5.8.2 5.8.0 5.7.0 5.6.0 5.000
history(cont.)
.
. . .
. .
.
26.0ct,1995
4.000
3.000
2.000
1.000
.
Dec.18,1987
.
July.18,2002 March.21,1991 March.28,2000 July.26,1998 Oct.18,1989 Dec.18,2007 Feb.21,1988 Oct.18,1994 Oct.23,2003
(T)
(Perl Time)
4/25
Features
Perl: is flexible and easy to learn is functional and interpreted language is Open Source software is powerfull string manipulation language supports OOP is portable language have automatic memory management uses dynamic typing
5/25
Syntax
Things are different shoud look different. #!/usr/bin/perl
Path to the Perl interpreter
#This is my first
program
Comments
Data objects
Elementry
int real char string
Data structures
FIRST
str 345
7/25
Arrays
Scalar
array
@array = (4, 5, 6, 7);
@array2 = (A..J);
push(@array, 8); pop(@array);
Acssec
0 1 2 3 4
to array
# $element = 4
$element = $array[0];
the @ changes to a $ because elements are scalars
8/25
Associative
arrays
jack, 789);
Print $lookup{peter};
# get 123
@name = keys(%lookup);
peter
123
andrew jack
456 789
@code = values(%lookup);
Delete %lookup(jack);
Delete key & value
9/25
for
if
conditional
until
3 5 7 9
10/25
Operators
arithmetic ** *, / +, % ++, -Logical && || ! assignmen t **= *=, /= +=, -= %= >>=, <<= ^= ~(10010) ; #The COMPLEMENT op1>> op2; 128 >> 3; # output 1024 ~ bitwise << >> & ^ (xor) |
(negation)
01101
11/25
Operators(cont.
)
Comparison operators Equal numerical == string eq
!= <=>
numerical < > <= >=
ne cmp
string lt gt le ge
Subroutines
sub tells the interpreter you are declaring a function function name to call the function
local($num) = 50;
$area = $height * $width; printheight = $height.\n width = $width.\n area is $area.;
13/25
Subroutines(cont.)
Sub first {
14/25
Functions
string
functions
lc(STRING);
lc(ABC); # output is abc
$var Substr(STRING, OFFSET, LENGHT); = 1234bb789; substr($var, 4, 2) = aa; print var = $var; # output is 1234aa789
index(STRING, SUBSTRING);
index(I am a student, am); # return 2 index(I am a student, book); # return -1
15/25
Functions(cont.)
array
function
@f = sort(small, medium, large); # gets @f = (large, medium, large)
sort(ARRAY);
reverse(ARRAY) ;
split(PATTERN, STRING);
0 1 2 3
16/25
Regular Expressions
=~ & !~are important operators we use with REGEX
The pattern is a set of characters between //
=~ comparison operator
# output is Match!
17/25
REGEX - Substitution
Substitution operator
print $str\n;
Replacement string
Global replacement
#get AGAUGAUAU
Substitution changes the variable
18/2 5
REGEX - Translation
Translation operator
Replacement characters
# get TCTACTATA
19/25
Most data of any size is stored on computer as files Filehandles allow you to read a file from disc and store the information in memory
For output
20/2 5
File(example)
open(HANDLE, "< /file/path"); #open for reading open(HANDLE, "> /file/path"); #open for writing open(HANDLE, ">> /file/path"); # open for appending
<HANDLE>;
Reads 1line from Open file
close(HANDLE);
open(HPSW, > /SYS/PUB/HPSWINFO"); # open for input $one = <HPSW>; # read first line $two = <HPSW>; # read second line @therest = <HPSW>; # read all remaining lines close(HPSW); # close the file 21/2 5
Perl applications
It
uses in AI, genetic, industry, internet. Its one of the three Ps.(alonge with Python and PHP) Is very powerfull in 3D programming. It used as a glue language. works with XML and HTML. Its good network programming language. With perl you can even write a OS!!
22/25
References
Related links
Pratt, Trans W. /zelkowits, http://www.perl.com
Marvin V./programming language: design http://wikipedia.org and implementation/salkhorde, m.mahdi/khorasan publications. http://www.PRDEV.com http://billhails.net http://www.aj.com
24/25
25/2 5