|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: break statement
Date: Oct 13 1997 2:57PM
Gayatri Krishnan wrote:
>
> Hi,
> Can someone help me with the 'break statement with in a 'foreach'
> loop???
>
> I've an array @a with numbers (123, 124, 125)
>
>
> foreach $i (0 .. $#a) {
> if ($e[$i] == "123") {
> $code = "A";
> }
> elsif ($e[$i] == "124") {
> $code = "B";
> break;
> }
> elsif ($e[$i] == "125") {
> $code = "C";
> }
> }
>
> Problem is the loop doesn't break when 'a' is 124... instead it goes
> thru all the conditions and $code gets assigned C.
Perl uses 'last' for C's 'break' statement. If you had used the
'use strict' pragma this error would have been caught.
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@datamig.com -||- http://www.mbay.net/~mpeppler
|