Perl foreach 循环

Perl 教程 · 2019-02-26 21:57:22

Perl foreach 循环用于迭代一个列表或集合变量的值。

语法

语法格式如下所示:

foreach var (list) {
...
}

流程图

Perl 中的 foreach 循环

实例

#!/usr/bin/perl @list = (2, 12, 36, 42, 51); # 执行foreach 循环 foreach $a (@list){ print "a 的值为: $a\n"; }

执行以上程序,输出结果为:

a 的值为: 2
a 的值为: 12
a 的值为: 36
a 的值为: 42
a 的值为: 51

点击查看所有 Perl 教程 文章: https://www.codercto.com/courses/l/19.html

查看所有标签

Algorithms Illuminated (Part 2)

Algorithms Illuminated (Part 2)

Tim Roughgarden / Soundlikeyourself Publishing, LLC / 2018-8-5 / USD 17.99

Algorithms are the heart and soul of computer science. Their applications range from network routing and computational genomics to public-key cryptography and machine learning. Studying algorithms can......一起来看看 《Algorithms Illuminated (Part 2)》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具