Kyle Babich wrote:

> Does Perl have an in operator or something similar?
> If not how would I find out if a certain list has a certain element?
> 
> Thank you,
> --
> Kyle

simply loop through the list or array you have and see if you can find what 
you are looking for:

my @i = ( 1..100 );
my $found = 0;
#-- looking for 34
foreach my $j (@i){
        #-- exit as soon as possible
        $found = 1, last if($j == 34);
}

print $found ? "found 34\n" : "34 not found\n";

or use a hash for faster loop up:

my %h;
my @i = ( 1..100);
@h{@i} = ();
if(exists $h{34}){
        print "found 34\n";
}else{
        print "34 not found\n";
}

don't use hash if:

1. @i has duplicate value which you want to keep
2. order is important
3. @i is huge and takes up a lot of memory

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to