Lecture%2019%20-%20Perl%20Programming

Lecture%2019%20-%20Perl%20Programming - Lecture 19 Perl...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright @ 2009 Ananda Gunawardena Lecture 19 Perl Programming Perl (Practical Extraction and Report Language) is a powerful and adaptable scripting language. Perl became very popular in early 90’s as web became a reality. Perl is ideal for processing text files containing strings. Perl is also good for processing web pages containing tags of different types (image tags, url tags etc). These tags or substrings can be extracted using Perl commands. Perl programs are ideal for managing web applications, such as passwd authentication, database access, network access, and multi- platform capabilities. Perl is also good for working with html web forms, obtaining user inputs, enabling cookies and tracking clicks and access counters, connecting to mail servers, integrating perl with html, remote file management via the web, creating dynamic images among many other capabilities. Perl programs are not compiled but interpreted. Perl interpreter in your unix system can be found by typing h where perl It may show /usr/local/bin/perl /usr/bin/perl giving the path of the perl interpreter. Perl interpreter is used to run perl programs. Let us start with a simple Hello world program in perl. #!/usr/local/bin/perl print "Hello World\n"; WARNING: The #!/usr/local/bin/perl must be the first line in the file. DO NOT ADD comments # before that line Assuming this is in a file called hello.pl, we can run the program by typing h perl hello.pl Or you can set the executable permission for the file and run the program as follows. h chmod +x hello.pl h ./hello.pl
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright @ 2009 Ananda Gunawardena Scalars in Perl A scalar in perl is either a numeric (103, 45.67) or a string. A string is a sequence of characters where each character is represented by 8- bits. There is also null string or the shortest possible string that has no characters. A string inside single quotes (‘hello there’) is a literal string, and double quoted strings can have escape characters such as ‘\t’ (tab) inside them for formatting purposes. A double quoted string is very much like a C string. Strings in Perl Perl strings can be surrounded by single quotes or double quotes. Single quote means string must be interpreted literally and double quotes could have “\n” type escape characters that have special meaning. So for example print “hello world\n”; b prints the string hello world with a new line print ‘hello world\n’; b prints the string hello world\n Operators for Strings Strings can be concatenated using “.” Operator. So if we define two strings s1 and s2 and concatenate and store them in a string s3, you would do it like this in perl. $s1 = “hello”; $s2 = “world”; $s3 = $s1.$s2; Note that variable declarations are preceded by $. Other useful functions that can operate on strings are: substr($s,start, length) --- substring of $s from start of length index string, substring, position – look for first index of the substring in string starting from position index string, substring
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Lecture%2019%20-%20Perl%20Programming - Lecture 19 Perl...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online