> On Thu, Jul 05, 2001 at 11:59:48AM +0100, Mark Fowler wrote:
> > On Thu, 5 Jul 2001, David Cantrell wrote:
> >
> > > On Thu, Jul 05, 2001 at 10:43:48AM +0100, Leon Brocard wrote:
> > > > David Cantrell sent the following bits through the ether:
> > > >
> > > > > I wanted to overload == to tell me whether a list contained
> > > > > a certain scalar
> > > >
> > > > Hearing the word "in" is an indication that you probably
> > > > should have used a hash, not a list or array
> > >
> > > There are multiple occurences of the same value in the dataset, so I can't
> > > use a hash.
> >
> > use List::Util qw(first);
> >
> > if (first { $_ eq $element } @list)
> > {
> > print "yey!"
> > }
> >
> > Similar to `grep' in that it evaluates BLOCK setting
> > '$_' to each element of LIST in turn. `first' returns
> > the first element where the result from BLOCK is a
> > true value. If BLOCK never returns true or LIST was
> > empty then `undef' is returned.
>
> If I'm looking for the presence of a list element whose value is normally
> taken to be false (eg $element is zero) then it will never say "yey!".
>
> </picky>
if ($flagged){$NEG=-1}else{$NEG=undef);
react if member($_,@_) ;
sub member { my $target = shift;
for (0..$#_){
return $_ if $_[$_] eq $target;
}
return $NEG;
}