foreach statement in perl - Perl Views : 268
Tagged in : Perl
0 0
Send mail

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

By Geethalakshmi, On - 2010-09-17



    Login to add Comments .