perl之更多的控制结构
1.unless/if结构
unless 条件为假的时候 才执行语句块。
eg:
unless($fred =~ /^[A-Z_]\w*$/i){
print "The value of \$fred doesn't look like a Perl indentifier name.\n";
}
想让于:
if(! ($fred =~ /^[A-Z-]\w*$/i)){
print "The value of \$fred doesn't look like a perl indentifier name.\n";
}
2.unless 's else statements
unless(condition)
{
statements;##run when condition false
}
else
{
statements;##run when condition true
}
3.until / while 控制结构 <===反置关系
until(condtion)
{
body; ###run when condition false
}
4.表达式修饰符用 if/unless while/until
statements if/unless/while/until
eg:
print "$n is a negative number.\n" if $n <0;
&error("Invalid input") unless &valid($input);
$i*2 until $i > $j;
print "",($n+=2) while $n < 10;
&greet($_) foreach @person;
print "fred is '$fred' , barney is '$barney'\n " if $I_am_curious;
5.裸块(naked)控制结构
所谓裸块(naked)就是指没有关键字或条件的快。
eg:
while(condition){
body;
body;
body;
}
去掉关键字和条件表达式:
{
body;
body;
body;
}
naked block 可以提供一个临时词法变量的作用域。
6.自递增与自递减
7.for 控制结构
for、 foreach 在perl中完全等价。
8.循环控制
1.last 相当于break
2.next 相当于continuous
3.redo 表示回到当前循环块的开头,但不测试任何条件表达式或进入下一个迭代。
last/next/redo都是对最内层循环块。
9.逻辑操作符(&& ||)
逻辑操作符有短路问题。但perl的逻辑操作符short-circuit逻辑操作符的值是最后被计算的部分,而不是一个布尔值。
10.三元操作符(?:)
11.使用部分计算操作符的控制结构
特点:对于&& 、|| 、?:有个共同属性即依赖于左侧值的真假,他们可能计算或不计算一个表达式。
eg:
($a > 10) || print "why is it not greater?\n";
最新文章
- Spring中Aop的扩展及剖析
- Spring的定时任务配置(转)
- C#中jQuery Ajax实例(一)
- Darwin Streaming Server 6.0.3安装、订制、插件或模块
- nopCommerce的源代码结构和架构
- openStack telemetry/ceilometry 云平台资源监控度量
- curl: (6) Couldn’t resolve host ‘www.ttlsa.com’
- HttpSesstionActivationLIstener示例
- VueJs(12)---vue-router(导航守卫,路由元信息)
- Failed to mount component: template or render function not defined.
- Android加载图片的策略
- luogu 1550 [Usaco2008 Oct]打井 最小生成树+小技巧
- maven学习一(HelloWorld工程)
- ubuntu12.04安装Docker
- Windows 2012设置允许单个用户连接多个会话的方法
- 【代码笔记】iOS-长条蓝色button
- Hibernate系列之ID生成策略
- 获取的时候报cannot find package ";golang.org /x/net/context";,编译也报错误
- js处理url中的请求参数(编码/解码)
- IOLI crackme分析——从应用中学习使用radare2
热门文章
- 怎么快速对DB里的所有email进行校验
- SpringBoot | 启动异常 | 显示bulid success 无 error信息
- PostgreSQL-5-条件过滤
- 选择提示框UIAlertController 和网络状态判断AFNetworking
- [題解]luogu_P1613跑路(最短路/倍增)
- PHP 字符 正则表达式 +,*,?
- mongodb Gridfs操作
- hihocoder1831 80 Days
- 明白这十个故事-->;你也就参悟了人生 .
- COGS 696. [IOI1996][USACO 2.3] 最长前缀