in reply to join should polymorph on hashes

I'd rather have a map-like operator that can operate on an arbitrary number of elements at a time. Something like:

my $items = join('', multimap( 2, { $_[0] . '=' . $_[1] . "\n" } %ENV));

Maybe a little prettier, though.

Replies are listed 'Best First'.
Re (tilly) 2: join should polymorph on hashes
by tilly (Archbishop) on May 03, 2001 at 06:03 UTC
    Like this?
    sub multimap (&$@) { my $fn = shift; my $n = shift; my @res; while (@_) { push @res, $fn->(splice (@_, 0, $n)); } @res; } print multimap { "$_[0]=$_[1]\n" } 2, %ENV;
    I tried to reverse the order of the first two arguments, but then the prototypes misbehaved. Reminded me of why I usually don't try to use them.