perltutorial
root
The foreach loop allows you to do something to each value in an array.<BR>
A quick example is below:<BR><BR>
<code>
@numbers=(1,7,3,8,9);
foreach $number(@numbers){ #makes $number point to array value;
$number++; #$number is incremented by 1 which is reflected inside the actual array;
}
#Now if we print out all the numbers they should reflect our changes
#ie @numbers is now equal to (2,8,4,9,10);
foreach(@numbers){ #notice here we don't specify a variable so Perl uses its default: [perlman:perlvar|$_]
print "$_,"; #we print the changed numbers separated by commas
}
</code>