下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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作業(yè):
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監(jiān)視剪貼板變$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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 常州市溧陽中學高三地理一輪復習8海洋地理作業(yè)
- 第2講 分層作業(yè)
- 2025年中職道路橋梁(橋梁施工)試題及答案
- 2025年高職機械電子工程技術(機電控制技術)試題及答案
- 2026年中職第三學年(市場營銷策劃)促銷方案階段測試題及答案
- 中職第二學年(制冷和空調設備運行與維護)空調安裝調試2026年綜合測試題及答案
- 2025-2026年八年級語文(綜合鞏固)上學期試題及答案
- 2025年大學電力系統(tǒng)繼電保護與自動化(繼電保護應用)試題及答案
- 2025年大學水利水電工程管理(水利工程管理)試題及答案
- 2026年中職第二學年(國際貿易)國際結算綜合測試題及答案
- 醫(yī)學影像云存儲:容災備份與數據恢復方案
- 2025年衛(wèi)生系統(tǒng)招聘(臨床專業(yè)知識)考試題庫(含答案)
- 基建工程索賠管理人員索賠管理經典文獻
- 工業(yè)機器人專業(yè)大學生職業(yè)生涯規(guī)劃書
- 農貿市場消防安全管理制度
- 良品鋪子營運能力分析及對策研究
- 手術室中的團隊協(xié)作與溝通
- 五人制足球技術智慧樹知到課后章節(jié)答案2023年下電子科技大學
- 涉密人員匯總表
- 其他方便食品(沖調谷物制品)
- S7-200SMARTPLC應用技術PPT完整全套教學課件
評論
0/150
提交評論