Perl foreach loop
Perl foreach loop to iterate over a list or a set of values of the variables.
grammar
The syntax is as follows:
foreach var (list) { ... }
flow chart
Examples
#!/usr/bin/perl @list = (2, 12, 36, 42, 51); # 执行foreach 循环 foreach $a (@list){ print "a 的值为: $a\n"; }
The above program, the output is:
a 的值为: 2 a 的值为: 12 a 的值为: 36 a 的值为: 42 a 的值为: 51