100%(1)100% found this document useful (1 vote) 396 views24 pagesSL Unit 3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
— Segtp king orawogy. ie
UONT-3
ow u
Seva ction to RERLE
Pot rapa, :
Perl 4s & progamntig largyacg which ons oftegrolly
developed fos osex8 pt mmoanipwladton . ;
Ms jyiad use fs ertvacking fufoonahion from a tedt-ttle ‘
and prtwking uk veport for comer a Aenk {ile into
omcthes fosm.
aes 3s becoue ges AS wame after te experion, "
Prackteal Erhadkton £ Report hanquage".
»Progams wien tn Ferd are called pal scripts, wheres
supe, Programs to enecude perl sevipt ate called perk
Regen.
Scrigky :
LA sesiphing ov scvigt \wguont eo Progyaranding loxevog,
| For a spectah sunNime environmeitt Anak auchomedtes the.
execudten of tasks, |
UN sevip\ira, \anquosg con be viewed ar a domot pee
Janquvogp- for a pas\icular Enwironmenk WM care of scviptig
am appiecd ion, 4 As algo Kroon ad an extension
“Some of sofiptrg, Senqucroer Vke bash , Rides, Ruby
i Paulin, PekQs = Pease |
ea ees :
| A scviph oF seiipttogs lemquoae fsa Computes
| Abe a Seve Of commands within a.
vera, execuded wottreut boeing compiled.
Stle Capalle of
eee se side éscsipting, aquasys — Pek, PHP 2 Pathon
_ Chenl - side sctieting, Sawquoae - Savasertpt,
|. Program Tm general yds a sequence of trstrcctons
ile
Peagaoantvg Sonqvong
E Cometler oar ed
|. Move syrlan ond We 4,
coupled, :
= sConvesk ath the cede Ay
binary and run
For big and complex
e | Programs
te | » Fastes for large wde
* Bakr HE MOA
“eae seagecrwng
Jova, C¥ eke,
po
Yanquogr art Mke c, Crt,
so Wok a compider can Perform certain Lark,
ait is alse peat
Scripting Lomquoge
+ Swcler picker based
+ Reduced syrton and
loosely coupled
+ Run stakemenk by the
SKoakement.
= Smaller code
» Faster for small code
a No ercree memory
. Popwlas scripting Jamquoges
aw Mee patron « Savercrtpt,
Per, PAP, Ruby, eke,Ope sf Biri »
ie yea 4 dent MW AAAs
The wood ‘seri eo compara, cowl os
re osiqinators of ee ONIX of Me UNIX epercting vk
sue Mae Aeva ‘shell Sevipt! Csequence of commands) &
eAw Apple Macintosh Hypolasd application, one of the easly +
aperter’ systems :
The associated Hyper Tale Larquoge aloud dhe uses 46
AefMe sequences of aclons to be associated with :
prnouse cls oy movemerds, and dese were called 7
(sorpts: t
adwtttely a script os a sequence of commands & | {
| contacl an appliceion ov a device. \
OSctis hat
We Meron Cscetpting’ 8 now a days ued ucith thee
Aifevent meanings, |
DA new ole of Pegarnngirg ckich allaos applicattons to be
developed much faster than traditional metrals,
This skye of pregonning frequently vses a seviphing
lavayoae 40 ‘ndercomect Colt the ‘helt’ components {ral are
Xremselves iter Wa conventional \ewquoge.
« Appltcadions balk in Wts loay are somelines called *
que applications “and Ye scxiphing lerquege. is a@led a
‘glue \anguage’,
i Bg The us of Visual Basic 4o develop ava SVQ pr e—
buf Visual control.[DEA & SCipra \avquoge Xo wantipilale, ¢
audowake Mme facilikies of on exiskivg system. ili
q | tee, soigt IS used Ao conrol an oppltcadton that
by be pogammable Wwleeface Tee APL. are
ul
the apfieation is corstiucted Grom cellection of sbjecs
| pdrose properties cand melods ave exposed 40. the
r | oigking Language .
0 Ege Use of ‘Mew ride scripting ond. Dypeonte HTML 40
create “wkevackve Wel pages: 5
W)USq * scripting language with Ws wich’ function ally
we can use an allenakive So. a conventional ag -
for general Programming Aasks, pacticularly system a
| Prograrerntng and. system adwainistsation. ;
[ey Wendows NT sgtems uses PERL for admintetiation
Apache, has an embedded Perl imterpreles for Cal coins
Ocromacherrstics of seetin neers
fle Bad leak ond Mheaachive Use |
—While a few languages Ey Pe) howe comgiles Xho |
A |requices Me’ entire source progran, almost all seviplig,
oe _ Tanaaacgs Aves compile OF anterpret Kune by line.
ae Hany ie compile A" veaiions ave acdually complerely equivale.
Ind ko the (ukerpreter running, Leland Whe scenes.
a
®» Exonorny of expression
| 2,
some make heavy “se of panckuation,
"b= uso vastanks®
4 | and chow, Wenders while chhers emphasize Ena{ish-
|
| Wee" Functionally,
i ee1 fay hack of decacations, simple scopty, wales —
_Atvile Ane vues Wanyy they ae Qenevally fab ly
simple and adddttonal syntar ts mecessarg Ao alert
» Mew
Fletble Ayramte 4ypiry
= dn PHP, Python and Ruby, tne hype of vaatable.
‘s. only, checked vignt before Use
V) Easy access 45 othes proyams
— Whele alt Languages provide suppor fos OS
; functionally, seviphing \omquages generally provide amazin
and much more fundamental built support,
y Sopkisticated pattern matching and shitca, manipulatia
Hyny Wih Veveh dada *ypes
— Scxiphirg Lawguages provide suppork fox sets, didionaries
Vis and Auples fat a ndiaimum),
| @ose fe seit koege!
Soxipting anquages axe of duo kinds:
*)Fraditional scsipbing
| %) Modern scrptirg
4) Wwoddttoval_ scripting.
Ure ackivtties hich vequire Avedt btoral Scstptng
sadade- , Suskerm adninishredtion
Controlling Remote apphcaticns
System and application, extensions_Eagetenential Progicrrartirg |
command Une Auvterface |
ayrrodern_Sextehigh |
vtsval scxvightivg,
_ seriptalde components
cMewh -stde a Sewer-side Web script.
Old Seen
Web scvtph @ computes progyarrnmtng lavguage ee
addi, dynamic caupalaities fo wold wide - web Pages.
ormation to « page as a
oq \nlel scripting in ot wh
used tk on lek wre vecdey enter information
dhe osdey chepackmenct of
1t0des
fia, the weary, lot poned on Xo
Fane onttne business:
Web scxipting dwides
| %) Processivay forms:
| )Creakivg pages oth enhanc!
|
wes
id ardlo Mhree asens,,
ed Visual effecls 2 user
twckesacon
|W) Generedtorg, pages fon the Py from watestal held
me docdabase. a
| )Procewing wel fous’
|: Sn dhe ovigiveh Graplementalton of the web, when the
bed. for proceming Me iweformadion
as encoded and gent to the
by a CAL script hoc eventually
| form is Submit
|
jv entered boy Mae uses
| seave ‘
| & for peccensiigray
ane Wed browser
VO ynanic Web pageré
DD geanle Web fOAes aww
« Dyvartc HIME, ‘onplemended ty Ane Andernet a
—_. x the wold of VBA tos script, compound fen
oy weld of cVient-side and sesver-side web
scxighing.
the overlap ts cornglex, tov example web soi ptig
can be done WW VRaScxiph, SavaScript/Iscsipl, Perk wv
Teh.
Ts urivesse bas been enlarged, as Pel and tek
| ate used to Vungleeneret comagler appliced ons fox. large
“onqprfeadtons em Teh has been used to develop e
| alot banting system, and Perk vas been used to
tmplernent an ever prise. wide document ravage
-menk system for a eading cverospace company.eer parece ec
PERL, ue
Wax
BXave god vale:
« Pesh- vnawipuladles variable udich have a name,
" JA value ts oatqned, dolskored ty yattable by
assignment skectement of he, fori,
nome =value» : te
» Pech Usdinguishes lwo Sivqudas reine’ & plural ao
A Siogula name holds single chem of doka-Scabar walyy fr
A slasal vane for variable hold calleckion of data Hany of
( = On AOU oF lash : «\
7 Stating spectal chatacler of Vasfable deacta, the rag >
» of Ning Wek vame stands fox .
Mm &
b- Scalar data 2
@- Avy :
Le - Wash a
& - Sto vadine
wNalid Charackers are \ekkers, cigs junderstoved
Names wou also have non-alpranuinerfe chatorte :
other special Crararkes ‘
$3,949 Fs System vesecvell yore tr Pest]
«Sn conventional Prograrmnifea, \argvageay ned \eutables
ave Irdraiced by a declaredon, cdich Pt fiea the
mawe of the new variable ard alen wks ype , toh ch
Ackermtnes tre ¥end of value Wok cam he stored frwee vartalole and, toy Aroplt ccakion , Ane ppaskions ©
rod caw Noe casted cuk on Khok vartalle.
| Oxeteba®
| _ Per ’&s a cane sensitive Praqrannmig language,
the Alod’d amd dwoilk are tio different variables
mw esl.
Red yartalle name stacks usith efther 4. @ or %
&
dads falowed by Bev, oF moe lekkers, underscores and
Ped supports & keds of variables:
an *yScalans Comodo a single sslitvg ov numerfc value.
che verralde name wmusk stack wil a 4.
|) Aways Cowkodn a samdoraly accessed ovclered sek of
| volunes. Tre vatialle mame smusk ‘she wit a @
‘TMashes,. Contain Urey huey pates elficterelly cccersech
pes bey. The variable name musk ctact Wah a %,
+ Assiqnicg, values do variable fs done wrth she equal
wi to Ye lek of the > sign is
siqut=)- The operas
[ee ue or ee yatiqble, & the operand do the,
J qh % Ye volue stored in the vatiable.
les Eq, Stem 255 FEM 4s declaring a variable
v
ae: LY congas
naw = olin
h Gt. ipesh
of owe
wm | WornaltSema aabigmeds examples fo _ ster;
i ot
Bike price Eis qk
gdemevame = “Apple” 5 of
prt The price of one ddem-vame is Fiteon_ pig pe
gold coins. \n"s . Fa
Some. ovatgnenls_to_arpey, vauteblas 7
tke. pre Wisk = (5/8 20)
@ tkem- Prana = C" Mave, _ Apple “Caurok”): P
print “The price of one Hom-vaime lesttey & Hton-pite leg
; ty Bt
tei: a
© Some asiqnmecs 4o bath variable! ‘
: w
ya strgle clement. of a hash, the
sherh ioidh a followed by he
dement iw curly Losackels 44). *
Te veSer
vattable vant wast
key of the xequested
We weed te spectty dre bey value ptrs with che 8
key "=>" value syria. : b
de Bera. codaleg = (“Apple => ©, Rararal => g) :
pik “The price of one Apyle gs 4tem-cahaleg :
SNe Apple gold coins. Wn"
Scalar data thems ae combined Erba |wpreasiOns Using
opeeatas Perk has a lok of operators, ‘ !
Sn Mae following sec¥fors woe describe: the avccilable :
lltn Muir vakural a
P pyesto " : FAD YOUphrgs— a vitomneic,
“ gkvings tog Xe,
shegs,
, prtroelte_ operators;
it ? Q protdes Ye usual artthmnelte opevakors tuck
ice | Per
| aude
| manner of C*
opie ree tas
$c =ris 4d = 44;
Paertnosemnenk “The Sequence ts Sncremenk & a
ta Beauty dE dcees
a pock-Ancxemenk | The Sequevce ts asian 2 then
=| ‘novemends . :
| Bina, artthwelfe operations can be combined, esith
assignment, eqs datsas (Adds 3 do $4, bef
heeded So)
ba =hara: SniNalent ts)
“ancrernerce and auko-decremeveh Operators Ofte,
Y). | Rsdotna_ Operators ' |
Sn Perd most of Ae procemirg 4s done by wala, :
1
le &
{
|
| butlk-An funckions and CCompattan,
Sttrgs, SL ME, Wigh, Verge, cmp : ae
Nyhecfical operaor
wok —\
and - Re
or. = \\
park OK \ yt TY 4acio and dbeia3
Vv) Cond fonal ey MONA!
+ tS We one whose vale 2s chosen, $n, one of
Ye adlervadies ot vundine depending, on the outcome
of test,Rae F True exps, falseexp
ts ka =(haco)? ida
Ocerdel secluss
|
|
4 LA Combrol struckuse fs a block 9
£ Programming
rok analyees Vortables and chooses a Aiveclion em
whidh ko go based on Given parameters,
the herm Flow control detagls dhe dteeclione de
progam Lates ,
Block, 94 ts aw sequence, of One o% more statements
endesed fn curly losaces. :
aE {postive she
Awegative aah,
xs Conditions: AY condition fs a Perl exprerston whic
as evaluated Moa Boolean conkers Ab te evalucctes
to Be10 ov he emply, string the condition ts false,
Otherwise %k ts true,
+ Condétfoves usually make Use of relational Opescctoss,
| St Moral > 50
dota sso and Hotal < (09
A condgion can se negated, stg] Dperectoy
21
mw)
1 WE can
speciy Ahok ay” I(Hotal>so end Hota tos).
+ Condittonal eNpt exstOns u
“Conde onal exprersions should “be tn brackets,
ahrk Ahen-dlse skalements: cov HERR Io) “a
i : a
S4 (Atotal>o) dgade= Aly esky
ae wk etal \n! = Ast} (dob sso) fe
*Y CAtctal 20) Vegyade =" R
VU pitch “Holey! alee :
cle dade =F,
‘pt “bad dota \y Pcrre 7
«Aldkervalive to th -then-else*
To use a conditional eaprersion in glace of af they
~else conshucl, &
WUCba co) We
bb=0) s :
a ~Contes,, P= Chace) Porsts
(de=)
shakemenk qualtfters . 84
A Sivale stakemenk can ke followed by a condtkfonal ww
moder. \e
eae prink “ok!
f Yo Wolts>= ts;
| Privk “Wade Xt
+ 5 amd operat, G
dveltss =\. 2 and *
Avolts 4 ss,
TMs cm be worttten an:
prid( Chvelts> =)? “Ob\n's (Cgvelisa= 1.8) words
Repedition . :
: Repetition median “ncuder beth “esitvg Loops awd
>»ee
F coundiv, \oops
| Tettng_lcots:
| while (4a 4b)
| # Lda>4b)
| § saz da-$b;
at
4b =4b-4a;
pet
ge encccukes yell We condlttton & false,
Reve “urnkl" %s used to Improve the veadalsltty.
& dae 2 wil da s$b,
*h
Do loop (RK fs bug lk-ta uncles xodher than a
wackruck, Here, Me condition && desled afer
| sywkackic w
bloc, so We block fs execected. ccf
lhe erecukton of the
least once - do {
| Be
| A uléle fal =4b;
+ dou (41245 Se=lo4it+)
' 44. squone = heads
, is © BING AL sqoate Wy
foreach $iCl. AO)
' Bi-Squate =F $7,
_y Print wh ALA esque" 5s
p S Aw . i
peo te ward bo doe dhe Teel of valtts and | *
othe ave A
each olgech of the \tsk ts termed ad an element, a
Elements can be numbers ov shilegs.
Sucka) @arayNome = Celement 4, clement2, ---) s
Accersieg awreuy in_ perl; + :
vo aceems a single element of a perk aera , GSE 4
Wb) stan. before vatiale name. We caw assume thak dig 4
~epreserde Singular vedic & @ sian vepeseds plural values,
Nartable nae wrll be followed by 'sqrate laces
toh auden enstde TL, we cam aecers an anray.
sgl, @araypline = Came Mags);
horgplme CE ste brackets N
Wawa
Perl_Arvou, functions :
slle can add o¢ semove an clement from an ava
sive Some As¥euy Sunckfong,
*) Push on asxciy
+ ot helps fo, append a new element the end of the
ONY qe Saray s (*ptat yea);
push Garay, * blye"
ok prin aroun
pink ved blue
| The pop array funct
fon vernover the last elementpor Garvan 5 red
priv “@array\n'
off
pink
" shit on Avro +
Gk vermoves dhe let mosh element of an array &
qh tua shorlen Ye aie by th
MS) oat @ariay = C'ptiven, Wed)
i high @arrar 5
pvt “@arvradn" »
sed
a)Uushttt on arrays
| ot helps ko adda vnew element ack the start of
the anton.
[ee Gang =Ctpinks HB);
unskapt @arven Sovarge”s
ole. pri “@avieyn';
Orawge pint ved
Outs
cA perd Vist
week ko use patertthests 2 comma operators to
cowstrurk a lsd.
| sEadk value tm the Vet ts called list clement
| Lk clemerds ote Yudlened and ordered.
=|
RS a sequence of scallat values, Weveer to each element ba ais postion, @
We om
dinple Wks:
&)4 — comply Kot -
(i, 20, a0); — Ws of Srdbegers a
(eRe ast Mat), — Usd of strfigs, ce
+fe psd Weck wo contain elements trot have differen *
doka types. This Hod of Uist ts calle a cowsgler Mal, *
way Au=10; :
my os fa skeirgt ; :
u
Pived (*comaley (tat) ba 5/0");
Flodtentra ttt, ‘
TA sh tastde a lesk , Perl aukowaht cally Flakteng
ye Yakesral st
& (2d. &(s/6))
(2,31 & 5/6)
(C2034), 5.6)
Accesirg ts! 7
wWe can acces He eleweds of & lesk by using
Yo aero-bared iuder. To access We wh elernered, We
peed fo pak (aa) inden inside Sqvare \siacleeds,
syd’, A\itNawel iden];
Rowaps’ Per alowns gr to leuild a Het bated ona
or chasackeis.
--. 100)
is Cl \
% Ca ae x) ’
AL ane sane [sls
Owe of nwambets .[quale Ty
(the bashes as the mosk ersenttal and ingluenttal
A ace ak He Reh, nt
| A hat fs + Group of Feyvalue pairs.
ithe eye ee Untque sttrgs @ values ave scalar
valued: :
ve! “\ashes ae declared Uetng omy eqoord.
| the variable name starts with a (%) Sign.
“Hashes are same Vike as arrays, bak hanahes are
uvdrde red and also dhe hash elements are acceteel
usivg 1S value while array elements ate accessed
using aks ander value.
.No repeating, keys owe aklowed tn hashes which
| wakes te Fed values unique ansible a hash.
Sarda | ray of vashName = C" bea" => Walue") 4°
| Accersivg
| Te access “eleweuts of hash, (Hsin used
- gre vattable name . And then Fey element fs
coritlen wistde $k braced.
©) eqe mg oh Capitals = (edadiat => “neo Dealt
| =>" Margo’);
| pring * deaptlals j'Andia'y\n" »
°
a
NV Frutt
| ole
| New peli
A Bag a I llcro
|
Sees. 4
» Strings ave an emential pak of Mhe Perd t q
Whey axe salar vettables, so Yhey shack wh) Sy,
LA shiteg, can be defined usithin 0 Steele quoteCty | 3) 94
vv double quote UY. a
«Sw pert, 40 declate a Mog, ase Sag" Feyoud betore
Vatable name,
A statog, can be initalised ant declared vstth ‘he =
Falloctra syntax,
my AvaxiableName =" "5,
othe operators mate %+ easy ko wantpulake a shty
fn Aefevend ways. There are too types of strirg,
operators, Thea ave | Dlonaberadion C. )
© Reber Montx) '
§)Concaderadion operator. !
Pec strings axe concaterated with at.) sign insted
ef C4) Sqn.
eq; KftrstName = “chststan',
SlastNome = “Grey
_ UallName = 44tidname, + HlastName +
% pit “MalNamedon's
Chsiskian Srey
KRepeXion operator:
Pek stitigs cam be vepeatel ao number of Hines
wth (x) vortable -
Ao
taeh aaa
gs Breck =O Thanks;
| goulput = Meck x2;
| prick “doukpat\n";
> oe hanes Thanks
Gpeen sok xeyet REeeess
efore | Pa
. A parte
the searoned For wn a chatackey shring,
An perk, partes ns ove, nos molly, enclosed Mn slash
charackess [deff
tng This vepresents the pattern del.
q Pe
whe ne pattern is found, a makch occtrrs,
= redefine petkesn = idef/
vnedchex vote wwe sting ak the |
Me chatackers.
wy 8S & sequence of ckatackexs 45 Bey
fr Sg
Hee, the parker
gerd, four © i
dk ‘| “We have patent mortching in Nhe Ubrecoy function
split @ascouy = spt C//, Aline);
phe Lhe pan (//) worches a singe space ,
“i gltts a Fl Suto woods,
[ defines special operators Hrok test whether
| pasttcala potters appears in a chasacler sting.
Jaw ar tabs tether a patrern fs rradched .
SL veubls a non-2er1o value ote tf ek fs found
0, ov false TF the pattern &s nok watched «
tohichea: Aveda = Ava = w/abel 5° > [ 7 Ns
%) Vo sat checks whether a partesn ts ma Weld ia
pn
Se vesulks 6 th Wf found 7
SK vesulls a non 210 value ZF A ts Mel famd- &
Reals exprens CXSONS |
A vequlat expicston ta shtg of ieee ted
Ackines Ye pattern os pattems you ae viewing,
A sequlat expcemion 4s also velevsed to od Yeagu ox
FEAEND- ;
is vequlas Capiewion can be evthey Simple ov complex,
depending, ow Ane pater You voant fo mad
~ad. Rxeaulk = = Avot |v [abel's .
Sarda sMeing = 0 ¥eqn)
The basic mehod for apply a vequlat exprerion ts
fo use Au poten dirding operas = 0 and la,
“The fHA_ Ofewdor es a tesh and fwatqwent epexcto,
There ave Arve vequlog enprersfon opeaors votlhin
Perk. 7 Moddy Regular enprersfon — wil
oSubsbitude regular eaprersi on - SII
> avatlebiale Regular exprersion — ill
Mekong F
‘A ped Junckion os subraine fs a qroup of
oe ee eeF edgdementS Yao Kogelner Pec torm oc spectfic tosh,
. |e word subroutines 5 used mod tn Perl '
TT
" pogo" \wcamse % &s created using eequord,
|
sul
We can de{ine he sulosoudines in Perl ts ag
id fallovos, suo subvoudne name.
ae \ Heboly of method 0+ subsouline,
To use Vis delined subsatine, WE need to call
: yhe Suoroudined. dy Perl suloscurtines can lee called.
ty passin, Yu aachurnenthe sh to th as Follows:
6
subvoukiye vamel asgunends— lf st)
| Se Sub area
dstd = 4;
4 velun aside € Aside),
HotalAvea = avea Ce);
eth Princ RotwlArea
in | Advantages :
rAd Velps us to reuse the code and mater the
proces of fending excor & debug cany,
| St dps tn oxgawtiring {he cole n steuctusah formal,
|
|
|
ip es eee eae
SE Rncrenes Xe ode readability .