On Thu, 5 Jul 2001, David Cantrell wrote:
> Mark Fowler:
> > 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!".
Oh Bollocks. You can obviously check the result of first for definedness
like so (which is what you should have been doing in the first place) :
print "yey" if (defined(first { $_ eq $element } @list));
..but that's not going to work if you're looking for undef. In this
highly unlikely situation you can do this horrible hack:
my $foo;
first { $foo = $_ eq $element } @list;
print "yey" if foo;
hmm.
Later.
Mark.
--
s'' Mark Fowler London.pm Bath.pm
http://www.twoshortplanks.com/ [EMAIL PROTECTED]
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}