perl中last的用法
在C语言中,如果想要退出一个循环,我们可以使用break。在perl中,没有beak这个关键字,但是perl却也提供了另外一个关键字,让程序从循环中跳出,那就是last。现在我们就看一下last的使用。 #! /usr/bin/perl my @array = (1 .. 100); 上面的程序,在foreach中,只会打印三个数字1,2,3就退出了,就好比执行时遇到break一样。 注意:last不能用于具有返回值得模块当中,例如子程序。 下面是perl上对last用法的注意提示: last cannot be used to exit a block that returns a value such as eval {},sub {},or do {},and should not be used to exit a grep() or map() operation. 转自:http://www.perlcn.com/perlbc/perljc/203.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Go语言中你不知道的Interface详解
- 基于go+vue实现的golang每日新闻浏览与检索平台
- I took time for preliminary study of the lua and php, i
- lua中逻辑运算符and与or的用法
- 比较实用的delphi 技术文章
- golang错误link reading body gob: attempt to decode into
- 可以的话
- LeetCode 1026. Maximum Difference Between Node and Ance
- 为什么Flink会成为下一代大数据处理框架的标准?
- 脚本语言lua笔记(6)Lua调用c++自定义函数