foreach statement in perl

by Geethalakshmi 2010-09-17 14:07:35

foreach statement in perl


This statement takes a list of values and assigns them one at a time to a scalar variable. Each time executing a block of code.

foreach $i (@some_list) {
statement1;
statement2;
}

The following example takes in element and mutliples it by 3 and replaces the original values in the array.

@a = (3, 5, 7,9);
foreach $one (@a) {
$one *= 3;
}

@a now equals = 9, 15, 21, 27

Tagged in:

1145
like
0
dislike
0
mail
flag

You must LOGIN to add comments