On Wed, Sep 20, 2000 at 08:05:20AM -0400, Webmaster wrote:
> David Nicol Wrote in RFC 262:
> >foreach $item (@items){
> >#print "$item was at location ",$item:n,"\n";
> >print "$item was at location ${item:n}\n";
> >};
> 
> What would really be nice here is an C<index> function, similar to the
> scalar version, that returns the index of the matching entry in a list. For
> instance:
> 
> my $n=0;
> foreach (@items){
>      print "Found It at position $n!\n" if /$seek/;
>      $n++;
> }
> Could be replaced by:
> if (my $n = arrindex( @items, $seek )) {
>      print "Found It at position $n!\n" ;
> }

Well if there ever is a way to shortcut grep this could be genera;ized
to

  my $index = grep { break if $_ eq $seek; 1 } @items;

assuming `break' causes the shortcut

An therefore allowing more comparisons than just eq

Graham.

Reply via email to