Perl: For loop
Loops run a particular piece of code as long as a certain condition remains. This is generally called flow control.
Perl has 'for' loop similar to C: for ($i=0;$i<10;$i++){ print "count is $i \n"; }
Another Perl for loop example:
for $i (1, 2, 3, 4, 5) {
print "$i\n";
}This loop prints the numbers 1 through 5 each on new line as follows:
1 2 3 4 5
The items in your perl for loop can be strings as well. As an example look below:
for $i (keys %month_has) {
print "$i has $month_has{$i} days.\n";
} for $var ('a', 'b', 'c', 'd') {
print "$var is the variable.\n";
}This would output:
a is the variable b is the variable c is the variable d is the variable
Some of the other details is here: Perl for

Post Comment