in reply to RE: scalarmap - some new perl syntax
in thread scalarmap - some new perl syntax

You are quite right about the join thing! I just wanted an example with a string and I didn't intend it to be a full blown join replacement!

See my reply to tilly for $a and $b.

I agree with you about having the initial value first, but I couldn't get it to work. Trying to prototype the subroutine as ($&@) meant that I couldn't call it for some reason.

If I try this :-

sub scalarmap ($&@) { local ($a, $b) = ( shift ); my $code = shift; foreach $b (@_) { $a = &$code; } return $a; } my @array = 1..10; my $sum = scalarmap 0, { $a + $b } @array;
Then when I run it I get
Array found where operator expected at scalarmap2.pl line 32, near " +} " (Missing operator before ?) syntax error at scalarmap2.pl line 32, near "} @array"
Which is puzzling...