PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Jim Anderson <jander at ml dot com>
Subject: Re: break statement
Date: Oct 13 1997 3:54PM

You've got a couple of problems here. First, if you realy want to
treat a number, e.g., 123, as a string, then you need to use 'eq' in
place of '=='. Second, use 'last' in place of 'break'.

Gayatri Krishnan sagely stated:
> 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.
> 
> 
> Thanks!
> 
> gayatri
> 
-- 
Jim Anderson			jander@ml.com
Consultant-at-large		jander@jander.com
				(212) 449-1598