Perl foreach Loop
The Perl foreach loop is used to iterate over the values of a list or collection variable.
Syntax
The syntax format is as follows:
foreach var (list) {
...
}
Flowchart
Example
#!/usr/bin/perl
@list = (2, 12, 36, 42, 51);
# Execute foreach loop
foreach $a (@list){
print "The value of a is:$a\n";
}
After running the above program, the output is:
a 的值为: 2 a 的值为: 12 a 的值为: 36 a 的值为: 42 a 的值为: 51Other Extensions
Perl Loops