It is used to iterate through each element of the array.
SYNTAX:
foreach LOOP_VAR (ARRAY) {
STATEMENTS
}
Example:
@array=(1..10);
foreach $var(@array)
{
print "The var value is $var"."\n";
}
Output:
G:\perl_programs>perl perl_foreach.pl
The var value is 1
The var value is 2
The var value is 3
The var value is 4
The var value is 5
The var value is 6
The var value is 7
The var value is 8
The var value is 9
The var value is 10
G:\perl_programs>
No comments:
Post a Comment