Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

RE: RE: scalarmap - some new perl syntax

by ncw (Friar)
on Sep 01, 2000 at 11:48 UTC ( [id://30689]=note: print w/replies, xml ) Need Help??


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...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://30689]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 07:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found