- 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
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
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
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
many thanks, jos and maxim, your suggestions were very helpful.
jennifer
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
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
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
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 "AF1" is in my list @myli
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, $whatever;
you can say
$myhash{$whatever}=1;
Then your search-loop collapses into