Perl foreach Loop
The Perl foreach loop is used to iterate over the values of a list or collection variable.
Syntax
The syntax 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";
}
Executing the above program will output:
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