Perl开发的学习-3
计算机作为一种计算工具,其优势在于执行重复任务和根据条件进行大量判断(因此循环语句,条件语句及顺序执行语句是计算机控制结构中基本语句,而与人类语言中句法完全不同)。 [root@windriver-machine test]# cat ctl.pl print "$a's value restore after the cycle:"; print "n change the var of cycles will impact the data of arrays:n"; foreach $c(@a){$c=4 if $c==2;} print "@an"; print "n may visit part elements of arrays:n"; print "n the defalut var of cycles is $_:n"; print "nfor and foreach is same:n"; print "using LABEL:n"; print "continue testn"; while($a++<10) change the var of cycles will impact the data of arrays: may visit part elements of arrays: the defalut var of cycles is $_: for and foreach is same: Perl语句根标准C/C++有很大的不一样,需要特别注意。 1) 条件语句,使用if(){} elsif(){} …else{},需要注意这里是elsif ,另外可以使用unless() {} 单选if 语句也是只有perl才有,() if() 或者() unless() 2) 循环条件语句,使用while(){} 或者do{} while() 及while() {} continue{}。 Until(){},do{} until(),util(){}continue{},特别是带continue,这一点与C完全不一样,需要特别注意.单选语句,一定要有结束条件。 3) 循环语句,使用for,foreach.注意这里面的控制last,next,redo,goto跟通常意义的理解也不一样的,需要特别注意。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |