This can be used in cases when you iterate through the variables in a array,when you
found the value you want to break out of the loop.
Example:
@array=(1..10);
foreach $var(@array)
{
last if($var==5);
print "The value of var is $var"."\n";
}
OUTPUT:
G:\perl_programs>perl perl_last.pl
The value of var is 1
The value of var is 2
The value of var is 3
The value of var is 4
G:\perl_programs>
No comments:
Post a Comment