

下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
Vine’sPerl
Simplestatement+
Vine’sPerlPerl入門和提 Lesson
Simple_statmodifier!!AlwaysevaluatesConditionbeforeexecutedoBLOCKwhilecond;runBLOCKoncebeforeevaluateprint"\$Aisnegitive!"if$A<0;die"SOS!"if($fail);$B=1/$Aunless$A==($sum,$j)=(0,1);do{$sum+=$j}while++$j<=$sum=0;$sum+=$_foreach(1..100);#loopson$hash{$key}=$vunlessdefned($hash{$key});#avoidover-$I=1;$J=0;$J+=$I++until($I>10);print$J;#==>55perl-e"printwhile<>;"<readme.txt1Vine’sPerlStatements-- Perl語法:查看perlsyn網(wǎng)Commentsin#Thisistheperlstyle/*Cstyle*/isnotforperl,nor//C++sytleCommentoutblockofif(0)……somevalidperl}PoC(Plainold
ControlFlow#Multi-choice:##Multi-choice:#not"elseif"#not"elseif"#but"elsif"if(…)…}elsif(…)…}elsif(…)…}elsif(…)…}else…}0.000,0,undef,"0",(but"0.0""00"isif(…)if(…)…}else…}if(if(…)…}
Vine’sPerl##line200#theprevious'#'mustonthefirstdie'foo';#格式是頂格的'#'可選的空格行號"文件名 #comparemodifiedexpressionif#comparemodifiedexpressionif…;expressionunless…; ControlFlow
Vine’sPerl
ControlFlow
Vine’sPerlwhile until
my$var;
èjumptocontinueblockandcheckèjumptobeginningofloop,nocontinueblockorcond
foreach
foreach$var(@list) èexitloopimmedia##beforeloopwhile(##beforeloopwhile(…){… …redoifany;nextifany;lastifany;…
##beforeloopuntil(…){…
…don'tsplicethe@list#!Sideeffectofforeachforeach@array=(1..5,#!Sideeffectofforeachforeach@array=(1..5,foreach(@array) #Say'for(@L)…'isalso$_="Five"if($_==5);#defaultloopvaris}#foreachloopisfasterthanfor#1234556789#1234FiveFive6789#loopbefore#checkdo#loopbefore#checkdo…}until(…);#similartodo{}do…}while(…);#redo,next,lastnot
continue#run##…}
foreach$var(0..10){$var*=$var;}#non for(start_exp;for(start_exp;condition_exp;step_exp)…}
ControlFlow
Vine’sPerl
ControlFlow :last,next,redo,
Vine’sPerlAvoidgoto,alwayswritethe"goto-lessfor($n=1,$sum=0;$sum<=1000;$n++)$sum+=for($n=1,$sum=0;$sum<=1000;$n++)$sum+=}print"n=$n;$sum-=$n--print"n=$n;#n=46;#n=45;foreach$a(@list){INNERLOOP:while($b){nextINNERLOOPif(seeperlsynforSWITCH:
nextOUTERLOOPif}}if(/^abc/){$abc=1;lastSWITCH;}if(/^def/){$def=1;lastSWITCH;}if(/^xyz/){$xyz=1;lastSWITCH;}$nothing=} perlpod-Plain
Perl
Subroutine
Vine’sPerlMixedperlcodeand BeginwithLines'=pod_cmdEndwith'=cut',i.e.returntoperlSomepodcommand=head1Yourheadline
參數(shù)在@_中,直接修改@_$_[i]Declarealllocalvariablesusingmy(…如果預(yù)先申明的函數(shù),sub函數(shù)名Checkcontextwithwantarray()調(diào)用時,函數(shù)名可加前綴&(強(qiáng)烈不推薦),其中&foo相當(dāng)=head2Yourheadlineover 項(xiàng)目列表開 項(xiàng)目列表結(jié)
sub$res=name($a,$b);@res=name$a,$b;subnamemy($arg1)=shift;my($arg2)=…
#pre 般沒有必要預(yù)先#但先作函數(shù)申明或定義,調(diào)用函數(shù)時就可以省略括號#call#alsocansay&name($a,#definesubroutine#copyargumentspod過濾命令:pod2text
my($result,@result);#declarelocal……wantarray()?@result:$result;#return}9Vine’sPerl作業(yè):
Subroutine
Vine’sPerl時,退出。附件名學(xué)號-提示:看Win32::Clipboard幫助下面是某次運(yùn)行過程顯示的結(jié)
Copyargumentsfrom@_(子程序 @_的內(nèi)容subname #definemy$arg1=shiftmy$ary2=shift; #thesameasshift@_my($arg3,$arg4)=@_;#copyargumentsmy(@list)=@_; #orinthisformat…?Functionwithsideeffect,@_傳遞實(shí)際參數(shù)的別名subSide_effect$_[0]=$_[0]*ClipboardtextClipboardtext:"notethatyouClipboardtext:"#!/usr/bin/perl-wusestr"Clipboardnottext.Clipboardchangedtext:"Perl模塊功能的些例子調(diào)用模use生成個剪貼板對my$Clip監(jiān)視剪貼板變$Clip-$Clip-獲得剪貼板的文本內(nèi)$Clip-my$a=Side_effect($a);# es10Side_effect(5);#fatalrun-timeerror.5is"對@_作shift,不改變數(shù)組的元素,無副作" #!/usr/bin/perl-
Vine’sPerluseprint"10:\t",pi(10),print"100:\t",pi(100),print"1000:\t",pi(1000),print"10000:\t",pi(10000),
print"100000:\t",pi(100000),print :\t", ),subpimy($count)=$_[0];$inside+=sqr(rand1)+sqr(rand1)<1while$count-->0;4/$_[0]*}subsqrmy($n)=return$n*}Vine’sPerl算pi#!/usr/bin/perl-wusestrict;print"10:\t",pi(10),print"100:\t",pi(100),print"1000:\
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 西方國家的國際貿(mào)易政策研究試題及答案
- 婦幼醫(yī)療保健服務(wù)行業(yè)政策法規(guī)對行業(yè)發(fā)展影響研究報告
- 軟件測試中的持續(xù)集成實(shí)踐試題及答案
- 網(wǎng)絡(luò)工程師考試的知識結(jié)構(gòu)試題及答案
- 公共政策的多元治理模式試題及答案
- 軟件設(shè)計師考試總結(jié)與反思試題及答案
- 破解西方政治考試的經(jīng)典框架試題及答案
- 2025年甲醇制烯烴項(xiàng)目合作計劃書
- 國際貿(mào)易單證實(shí)務(wù)(第3版)孫繼紅全套教案課件
- 電子音樂制作與演出企業(yè)制定與實(shí)施新質(zhì)生產(chǎn)力項(xiàng)目商業(yè)計劃書
- 食品安全體系FSSC22000-V6版標(biāo)準(zhǔn)要求及內(nèi)審員培訓(xùn)教材
- DZ∕T 0272-2015 礦產(chǎn)資源綜合利用技術(shù)指標(biāo)及其計算方法(正式版)
- 生命科學(xué)簡史智慧樹知到期末考試答案章節(jié)答案2024年中國科學(xué)技術(shù)大學(xué)
- 2024土地代耕代種協(xié)議書
- 《水電工程巖爆風(fēng)險評估技術(shù)規(guī)范》(NB-T 10143-2019)
- 預(yù)防術(shù)中低體溫Pdca 課件
- 胃癌診療指南(2022年版)
- 醫(yī)院物業(yè)人員交接方案
- 建筑施工行業(yè)應(yīng)急管理體系建設(shè)
- 逆變器技術(shù)規(guī)范書
- 【要填報的表格】園林行政許可申請表-樹木砍伐、移栽、修剪(洪山園林局專用)
評論
0/150
提交評論