Jonathan Scott Duff <[EMAIL PROTECTED]> writes:

> Will there be some shorter-hand way to say these?
>
>       @a = @grades[grep $_ >= 90, @grades];
>       @b = @grades[grep 80 <= $_ < 90, @grades];
>       @c = @grades[grep 70 <= $_ < 80, @grades];
>
> Granted, it's fairly compact as it is but I'm wondering if there's
> some way to not have to mention @grades twice per statement.

What's wrong with 
  
  @a = grep { $_ >= 90 }      @grades;
  @b = grep { 80 <= $_ < 90 } @grades;
  @c = grep { 70 <= $_ < 80 } @grades;

Or am I missing something? The examples you give seem to imply that
you should use the value of the things contained in @grades as indices
into @grades, and return the values thus indexed. There may be a good
reason for doing this, but one escapes me for now.

> Something like:
>
>       @a = @grades[$^_ >= 90];
>       @b = @grades[80 <= $^_ < 90];
>       @c = @grades[70 <= $^_ < 80];
>
> BTW, is there some other name for these things?  I only know to call
> them "list comprehensions" from python.  I've used the concept in
> other languages as well but never was it named.

I confess I never quite understood why the python folks were so proud
of list comprehensions, AFAICT they're just 'grep' and 'map' given
fancy descriptions.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Reply via email to