

下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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網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
參數在@_中,直接修改@_$_[i]Declarealllocalvariablesusingmy(…如果預先申明的函數,sub函數名Checkcontextwithwantarray()調用時,函數名可加前綴&(強烈不推薦),其中&foo相當=head2Yourheadlineover 項目列表開 項目列表結
sub$res=name($a,$b);@res=name$a,$b;subnamemy($arg1)=shift;my($arg2)=…
#pre 般沒有必要預先#但先作函數申明或定義,調用函數時就可以省略括號#call#alsocansay&name($a,#definesubroutine#copyargumentspod過濾命令:pod2text
my($result,@result);#declarelocal……wantarray()?@result:$result;#return}9Vine’sPerl作業:
Subroutine
Vine’sPerl時,退出。附件名學號-提示:看Win32::Clipboard幫助下面是某次運行過程顯示的結
Copyargumentsfrom@_(子程序 @_的內容subname #definemy$arg1=shiftmy$ary2=shift; #thesameasshift@_my($arg3,$arg4)=@_;#copyargumentsmy(@list)=@_; #orinthisformat…?Functionwithsideeffect,@_傳遞實際參數的別名subSide_effect$_[0]=$_[0]*ClipboardtextClipboardtext:"notethatyouClipboardtext:"#!/usr/bin/perl-wusestr"Clipboardnottext.Clipboardchangedtext:"Perl模塊功能的些例子調用模use生成個剪貼板對my$Clip監視剪貼板變$Clip-$Clip-獲得剪貼板的文本內$Clip-my$a=Side_effect($a);# es10Side_effect(5);#fatalrun-timeerror.5is"對@_作shift,不改變數組的元素,無副作" #!/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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 服務協議和合同
- 食堂合同終止協議
- 購銷合同的增補協議
- 職工合同聘用協議
- 豆制品合同協議
- 電子屏采購合同
- 培訓學校校長聘用合同
- 跨境電商海外直郵合同范本模板
- 沒有房產證房屋買賣合同
- 小程序開發合同
- 湖南邵陽農商行招聘真題2024
- 2024年國家藥品監督管理局直屬單位招聘考試真題
- 2025年4月自考00537中國現代文學史押題及答案
- 2025智能家居系統供應及安裝施工合同
- 環境科學概論考研真題及解答
- 建筑工程一級安全教育內容
- 商業地產租賃運營手冊
- 2024-2025學年江蘇省南京市鼓樓區樹人中學七年級下學期英語3月學情調研卷(原卷版+解析版)
- 陽光心理健康成長(課件)-小學生主題班會
- 蓄勢而行:2040年全球汽車行業前景展望-羅蘭貝格
- 房屋市政工程生產安全重大事故隱患判定標準(2024版)檢查指引(西安住房和城鄉建設局)
評論
0/150
提交評論