

下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 27530-2025牛出血性败血症诊断技术
- 建筑装修施工合同书
- 电子商务平台搭建及运营服务协议
- 咨询服务代理合同
- 应届毕业生顶岗实习协议书
- 游戏开发授权合作协议
- 房地产开发权益转让合同
- 外接电源合同协议
- 的担保借款合同
- 汽车零部件制造技术转让合作协议
- 耳鼻喉科患者的疼痛管理
- JGJT10-2011 混凝土泵送技术规程
- 2023版设备管理体系标准
- 第7课互联网应用协议 课件 2023-2024学年浙教版(2023)初中信息技术七年级上册
- 特殊问题学生记录表
- 中药功效快快记忆法(完整版)
- 01S201室外消火栓安装图集
- 电机与电气控制技术PPT完整全套教学课件
- 中国音乐学院音乐基础知识(四级)(基本乐科)备考试题库(含答案)
- 装饰材料复试清单
- 有限公司事业合伙人管理办法
评论
0/150
提交评论