develooper Front page | perl.perl5.porters | Postings from November 2000

IDEA: more for-like map and grep?

Thread Next
From:
Jarkko Hietaniemi
Date:
November 20, 2000 17:10
Subject:
IDEA: more for-like map and grep?
Message ID:
20001120191010.A19427@chaos.wustl.edu
While doodling with an Eternity Project (TM) of mine it came to me that
it would be nice to be able to alias also other variables than the usual
$_ when using map() and grep(), like we can in for(each).  If we can do

	for (@a) { ... $_  ... }
	for $a (@a) { ... $a  ... }
	for my $b (@a) { ... $b  ... }

why can't we

	map { ... $_ ... } @a
	map $a { ... $a ... } @a
	map my $b { ... $b ... } @a

and

	grep { ... $_ ... } @a
	grep $a { ... $a ... } @a
	grep my $b { ... $b ... } @a

Being able to 'rename' the iteration variables should be even handier
with nested maps/greps:

	grep $a { ... $a .... grep $b { ... $a ... $b ... } ... } @a

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About