Piers Cawley wrote:
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.
I don't see why I'd want to do it with arrays, but...

%a_students = %grades{grep /^a/i, keys %grades};





Reply via email to