7
Perl Introduction to Perl

Perl101a Example

Embed Size (px)

DESCRIPTION

Perl tutorial

Citation preview

Perl Introduction to Perl

References• Learning Perl - Randal L Schwartz, Tom Phoenix and brian d foy

• http://www.perl.org/books/beginning-perl/• http://learn.perl.org/

History of Perl What when who and why of Perl

What “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”

Who, when and why Larry Wall created Perl in mid-1980s He was working on generating reports from Usenet news like

hierarchy of files and awk was not good enough for him He wanted something easy enough and available like shell

scripting but powerful enough like a high level language like C

Virtues of Perl Perl is easy to use

Though may not be easy to learn,# if not practiced

Perl is fairly unlimited

Can even be used to write Firmware for HW but best fitted for what it was invented for

Perl is mostly fast

Since it is so close to low level language, interpretation and execution is fairly fast.

Perl is very scalable

Perl is the Camel that represents it :)

Well adapted to the conditions it is used in/for

A bit Ugly

Most common use Perl is most commonly used as a format convertor

Output from one tool to be re-formatted so that it can be used as input It is used to parse through a tool output/report and provide a concise result Extracting data from different files and building tables for graphical

representation (pivot table, graphs etc) Perl is also used extensively as back-bone for the different flows

Using numerous default and configurable options passed using different user inputs and files to provide a fairly re-usable flow.

Perl is used to automate regular hacks Perl is used extensive for application/websites over the internet along with XML

A Perl Program/Script “Enough of the history and geography we are here to learn to use Perl !!!”

Perl program is basically a text file. Use your own favorite text editor Some provide the benefit of syntax highlighting aiding debug

Perl is an interpreted language, not compiled. Perl program can either be passed as an argument to command line perl

interpreter perl <perl program>

Or it can run by including the perl interpreter within your program as the first legal line in your program #!/usr/bin/perl And run the program by assigning it execute permissions and running

it directly on terminal.

First Perl Script“Why is this always 'Hello world'?”

#!/usr/bin/perl#example of a line commented.print “Hello, world!\n”; # example of comment. Important observations

White spaces like space, tab, newline are insignificant in the syntax Comments start with '#' sign and end with end of line #!/usr/bin/perl is the least portable part in a Perl script No main routine, everything not in a sub-routine is part of main Most statements in Perl end with a ';'