sorry -- that should read
if you're creating the list element-by-element like this:
push @mylist, $whatever;
you can replace it with this:
$myhash{$whatever}=1;
-----Original Message-----
From: Mooney Christophe-CMOONEY1
[mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 26, 2001 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, $whatever;
you can say
$myhash{$whatever}=1;
Then your search-loop collapses into
if ($myhash{'AF00001'}) {...}
If, for some reason, you need the information in a list and not a hash, then
use a grep instead of the for loop:
if (grep /^AF00001$/, @mylist) {...}
HTH! ;)
-----Original Message-----
From: Jennifer Pan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 26, 2001 1:55 PM
To: [EMAIL PROTECTED]
Subject: if in a list
I want to test if "AF00001" is in my list @mylist;
I did:
foreach $LIST (@mylist) {
if ($LIST = "AF00001")
$boolean = 1;
else
$boolean = 0;
}
is there a more elegant way to do it?
many thanks
jennifer
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]