in reply to RE: scalarmap - some new perl syntax
in thread scalarmap - some new perl syntax
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 :-
Then when I run it I getsub 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;
Which is puzzling...Array found where operator expected at scalarmap2.pl line 32, near " +} " (Missing operator before ?) syntax error at scalarmap2.pl line 32, near "} @array"
|
|---|