Perl foreach loop
The Perl foreach loop is used to iterate the value of a list or collection variable.
Grammar
The syntax format looks like this:
foreach var (list) { ... }
Flow chart
Instance
#!/usr/bin/perl @list = (2, 12, 36, 42, 51); # 执行foreach 循环 foreach $a (@list){ print "a 的值为: $a\n"; }
The above procedure is performed and the output is:
a 的值为: 2 a 的值为: 12 a 的值为: 36 a 的值为: 42 a 的值为: 51