Perl foreach cycle
Perl foreach
loop is used to iterate over the value of a list or collection variable.
Grammar
The syntax format is as follows:
foreach var (list) {
...
}
Flow chart
Example
#!/usr/bin/perl@list=(2,12,36,42,51);# executeforeach
circulateforeach$a(@list){print"a's value is:$a\\n";}
Execute the above program, and the output is as follows:
The value of a is: 2
The value of a is: 12
The value of a is: 36
The value of a is: 42
The value of a is: 51