Monday, July 18, 2011

next keyword perl

The next keyword lets you skip the rest of the statement block and start the next iteration.
It can be used in cases where you want processing only for selected array elements and want
to ignore the rest.



Content of the perl file is:
@array=(1..10);
foreach $var(@array)
{

next if ( $var == 5 || $var == 6 );
print "The var value is $var"."\n";
}

OUTPUT :

G:\perl_programs>perl perl_next.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 7
The var value is 8
The var value is 9
The var value is 10

G:\perl_programs>
In this case as you may see the var value 5 and 6 are not printed due to the next statement.

No comments:

Post a Comment