if in a list

2001-07-26 Thread Jennifer Pan
I want to test if "AF1" is in my list @mylist; I did: foreach $LIST (@mylist) { if ($LIST = "AF1") $boolean = 1; else $boolean = 0; } is there a more elegant way to do it? many thanks jennifer -- To unsubscribe, e-mail: [EMAIL PROTEC

RE: if in a list

2001-07-26 Thread Mooney Christophe-CMOONEY1
ROTECTED]] Sent: Thursday, July 26, 2001 1:55 PM To: [EMAIL PROTECTED] Subject: if in a list I want to test if "AF1" is in my list @mylist; I did: foreach $LIST (@mylist) { if ($LIST = "AF1") $boolean = 1; else $boolean

RE: if in a list

2001-07-26 Thread Venkat Mohan
One thing When you compare strings use "eq" string comparition operator. Not "=" -Venkat -Original Message- From: Jennifer Pan [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 11:55 AM To: [EMAIL PROTECTED] Subject: if in a list I want to test if &qu

RE: if in a list

2001-07-26 Thread Mooney Christophe-CMOONEY1
001 2:09 PM To: [EMAIL PROTECTED] Subject: RE: if in a list That depends on what you're using @mylist for. If you're simply using it to check to see if an element is in the list, then use a hash instead. If you're creating the list element - b push @mylist, $w

Re: if in a list

2001-07-26 Thread Brett W. McCoy
On Thu, 26 Jul 2001, Jennifer Pan wrote: > I want to test if "AF1" is in my list @mylist; > > I did: > > foreach $LIST (@mylist) { > if ($LIST = "AF1") > $boolean = 1; > else > $boolean = 0; > } > > is there a more elegant way to do it? Sure is. F

RE: if in a list

2001-07-26 Thread Jennifer Pan
many thanks, jos and maxim, your suggestions were very helpful. jennifer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: if in a list

2001-07-26 Thread Jos I. Boumans
I'd actually be surprised if that works... let me point out a few things: if ($list = 'foo') will always be true.. you are assigning 'foo' to $list what you want is probably 'eq' the if block also needs curly brackets {} around it, especially if you want to use the 'else' part more so, assumign

Re: if in a list

2001-07-26 Thread Maxim Berlin
Hello Jennifer, Thursday, July 26, 2001, Jennifer Pan <[EMAIL PROTECTED]> wrote: JP> I want to test if "AF1" is in my list @mylist; JP> I did: JP> foreach $LIST (@mylist) { JP> if ($LIST = "AF1") JP> $boolean = 1; JP> else JP> $boolean

Re: if in a list

2001-07-26 Thread Michael Fowler
On Thu, Jul 26, 2001 at 11:24:12PM +0400, Maxim Berlin wrote: > Thursday, July 26, 2001, Maxim Berlin <[EMAIL PROTECTED]> wrote: > > MB> $boolean = grep /AF1/,@mylist; > sorry, incorrect sample. should be: > $boolean = grep /^AF1$/,@mylist; > with first regexp you catch every string, that

Re: if in a list

2001-07-26 Thread M.W. Koskamp
- Original Message - From: Brett W. McCoy <[EMAIL PROTECTED]> To: Jennifer Pan <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, July 26, 2001 9:12 PM Subject: Re: if in a list [...] > > Here's how I would code this: > > foreach (@mylist

Re[2]: if in a list

2001-07-26 Thread Maxim Berlin
Hello Jennifer, Thursday, July 26, 2001, Maxim Berlin <[EMAIL PROTECTED]> wrote: MB> $boolean = grep /AF1/,@mylist; sorry, incorrect sample. should be: $boolean = grep /^AF1$/,@mylist; with first regexp you catch every string, that contain 'AF1'. thanks to Mooney Christophe. Best w