Perl  Programming<br />
Topics<br />Introduction to Perl<br />Variables<br />Scalars<br />Arrays<br />Hashes<br />Regular Expressions <br />
Introduction<br />Perl – Practical Extraction and Reporting Language<br />Developed in 1987 by  Larry Wall<br />Filenames ...
Introduction<br />Perl scripts are interpreted in the command or shell prompt and even in the browser. <br />If it in the ...
Introduction<br />Go to the command prompt  and execute the command <br />perl filename.pl<br />In the browser, type http:...
Perl Variables<br />Scalars ($)<br />Numbers or Strings or reference<br />Started with a $ symbol <br />Ex. $string=“Hello...
Scalars<br />$x = 12345; # integer <br />$x = 12345.67; # floating point <br />$x = 6.02e23; # scientific notation <br />$...
Arrays<br />@a=(“hi”,”Hello”,”there”);<br />Print @a;<br />$c=pop @a; # last element “there” is stored in c<br />Push(@a,”...
Hashes<br />Uses a key value pair<br />Key is usually a string literal<br />Example<br />%hash=(“Tom”,33,”mike”,23,”john”,...
Regular Expression<br />Matches a word or a phrase or even a character trying to match a pattern<br />Meta characters<br /...
Upcoming SlideShare
Loading in...5
×

Perl programming tsp

1,196

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,196
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Perl programming tsp

  1. 1. Perl Programming<br />
  2. 2. Topics<br />Introduction to Perl<br />Variables<br />Scalars<br />Arrays<br />Hashes<br />Regular Expressions <br />
  3. 3. Introduction<br />Perl – Practical Extraction and Reporting Language<br />Developed in 1987 by Larry Wall<br />Filenames should have the extension of .pl<br />Runs under windows and linux<br />The first line of perl under linux is <br />#!/usr/bin/perl<br />The first line of perl under windows is<br />#!c:/perl/bin/perl.exe<br />
  4. 4. Introduction<br />Perl scripts are interpreted in the command or shell prompt and even in the browser. <br />If it in the browser, a Http header should be set like<br />print “Content-type: text/html nn”;<br />First example<br />#! C:/perl/bin/perl.exe<br />print “Content-type: text/html nn”;<br />Print “Hello World “;<br />
  5. 5. Introduction<br />Go to the command prompt and execute the command <br />perl filename.pl<br />In the browser, type http://localhost/filename.pl<br />
  6. 6. Perl Variables<br />Scalars ($)<br />Numbers or Strings or reference<br />Started with a $ symbol <br />Ex. $string=“Hello “; $a=200; $x=2**3;<br />Arrays (@)<br />List of scalar data<br />Defined by an @ symbol<br />@s=(“hello”, ”world”);<br />Hashes (%)<br />Complex list with both a key and a value part for each element of the list.<br />Defined by a % symbol<br />%ages = ("Jerry", 45, "Tom", 22, "Vickie", 38);<br />
  7. 7. Scalars<br />$x = 12345; # integer <br />$x = 12345.67; # floating point <br />$x = 6.02e23; # scientific notation <br />$x = 4_294_967_296; # underline for legibility <br />$x = 0377; # octal <br />$x = 0xffff; # hexadecimal <br />$x = 0b1100_0000; # binary<br />$x=“Hello” # string literals<br />Double quotes – variables are interpolated<br />Single quotes – variables are not interpolated<br />
  8. 8. Arrays<br />@a=(“hi”,”Hello”,”there”);<br />Print @a;<br />$c=pop @a; # last element “there” is stored in c<br />Push(@a,”here”);<br />Print @a;<br />Print $a[0]; #index starts at 0, so prints hi<br />
  9. 9. Hashes<br />Uses a key value pair<br />Key is usually a string literal<br />Example<br />%hash=(“Tom”,33,”mike”,23,”john”,19);<br />Print %hash;<br />@k=keys %hash;<br />@v=values %hash;<br />$count=keys %hash;<br />While(($keys=>$values)=each %hash)<br />{print “$keys=>$values”.”<br/>”;}<br />
  10. 10. Regular Expression<br />Matches a word or a phrase or even a character trying to match a pattern<br />Meta characters<br />Pattern Modifiers<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×