Perl programming tsp
-
Upload
t-s-pradeep-kumar -
Category
Education
-
view
1.160 -
download
0
Transcript of Perl programming tsp
![Page 1: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/1.jpg)
Perl Programming
![Page 2: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/2.jpg)
TopicsIntroduction to PerlVariables
ScalarsArraysHashes
Regular Expressions
![Page 3: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/3.jpg)
IntroductionPerl – Practical Extraction and Reporting
LanguageDeveloped in 1987 by Larry WallFilenames should have the extension of .plRuns under windows and linuxThe first line of perl under linux is
#!/usr/bin/perlThe first line of perl under windows is
#!c:/perl/bin/perl.exe
![Page 4: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/4.jpg)
IntroductionPerl scripts are interpreted in the command
or shell prompt and even in the browser. If it in the browser, a Http header should be
set likeprint “Content-type: text/html \n\n”;
First example#! C:/perl/bin/perl.exeprint “Content-type: text/html \n\n”;Print “Hello World “;
![Page 5: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/5.jpg)
IntroductionGo to the command prompt and execute the
command perl filename.pl
In the browser, type http://localhost/filename.pl
![Page 6: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/6.jpg)
Perl VariablesScalars ($)
Numbers or Strings or referenceStarted with a $ symbol Ex. $string=“Hello “; $a=200; $x=2**3;
Arrays (@)List of scalar dataDefined by an @ symbol@s=(“hello”, ”world”);
Hashes (%)Complex list with both a key and a value part for each
element of the list.Defined by a % symbol%ages = ("Jerry", 45, "Tom", 22, "Vickie", 38);
![Page 7: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/7.jpg)
Scalars$x = 12345; # integer $x = 12345.67; # floating point $x = 6.02e23; # scientific notation $x = 4_294_967_296; # underline for legibility $x = 0377; # octal $x = 0xffff; # hexadecimal $x = 0b1100_0000; # binary$x=“Hello” # string literalsDouble quotes – variables are interpolatedSingle quotes – variables are not interpolated
![Page 8: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/8.jpg)
Arrays@a=(“hi”,”Hello”,”there”);Print @a;$c=pop @a; # last element “there” is stored
in cPush(@a,”here”);Print @a;Print $a[0]; #index starts at 0, so prints hi
![Page 9: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/9.jpg)
HashesUses a key value pairKey is usually a string literalExample
%hash=(“Tom”,33,”mike”,23,”john”,19);Print %hash;@k=keys %hash;@v=values %hash;$count=keys %hash;While(($keys=>$values)=each %hash){print “$keys=>$values”.”<br/>”;}
![Page 10: Perl programming tsp](https://reader036.fdocuments.net/reader036/viewer/2022082702/55501345b4c905af648b4a22/html5/thumbnails/10.jpg)
Regular ExpressionMatches a word or a phrase or even a
character trying to match a patternMeta charactersPattern Modifiers