

下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
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(…如果預先申明的函數(shù),sub函數(shù)名Checkcontextwithwantarray()調用時,函數(shù)名可加前綴&(強烈不推薦),其中&foo相當=head2Yourheadlineover 項目列表開 項目列表結
sub$res=name($a,$b);@res=name$a,$b;subnamemy($arg1)=shift;my($arg2)=…
#pre 般沒有必要預先#但先作函數(shù)申明或定義,調用函數(shù)時就可以省略括號#call#alsocansay&name($a,#definesubroutine#copyargumentspod過濾命令:pod2text
my($result,@result);#declarelocal……wantarray()?@result:$result;#return}9Vine’sPerl作業(yè):
Subroutine
Vine’sPerl時,退出。附件名學號-提示:看Win32::Clipboard幫助下面是某次運行過程顯示的結
Copyargumentsfrom@_(子程序 @_的內(nèi)容subname #definemy$arg1=shiftmy$ary2=shift; #thesameasshift@_my($arg3,$arg4)=@_;#copyargumentsmy(@list)=@_; #orinthisformat…?Functionwithsideeffect,@_傳遞實際參數(shù)的別名subSide_effect$_[0]=$_[0]*ClipboardtextClipboardtext:"notethatyouClipboardtext:"#!/usr/bin/perl-wusestr"Clipboardnottext.Clipboardchangedtext:"Perl模塊功能的些例子調用模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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024國際商業(yè)美術設計師考試知識點試題及答案
- 教師資格考試中的創(chuàng)新能力與研究實踐考查試題及答案
- 強化母豬產(chǎn)仔成功的分析的試題及答案
- 寺廟文學面試題及答案
- 哲學考研考試題及答案
- 文物修復考試題及答案
- 教師資格證考試前必讀知識試題及答案
- 派對精神測試題及答案
- 2025-2030中國生命科學受控物質訂購系統(tǒng)行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略研究報告
- 2025-2030中國瓷磚及其印刷行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略研究報告
- 2025屆重慶市雙福育才中學中考化學最后沖刺卷含解析
- 光伏項目承包商的實施策略與計劃
- 管理學組織設計案例分析
- 消除艾滋病、梅毒和乙肝母嬰傳播項目工作制度及流程(模板)
- 2025年河南機電職業(yè)學院單招職業(yè)傾向性測試題庫有完整答案
- 2025年度汽車行業(yè)電子商務平臺合作開發(fā)合同
- 攝影拍攝合同畢業(yè)季拍攝合同
- 《個人所得稅申報贍養(yǎng)老人專項附加扣除指定分攤協(xié)議模板》
- 國家一級博物館運行報告2024
- 血液病早期發(fā)現(xiàn)-你不可忽視的健康防線
- 化工行業(yè)不合格品處理流程
評論
0/150
提交評論