Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: map sub to list?

by pldanutz (Acolyte)
on Sep 09, 2013 at 18:04 UTC ( #1053066=note: print w/replies, xml ) Need Help??


in reply to Re^3: map sub to list?
in thread map sub to list?

Cool. The actual code I had was more complex and warranted a function. I posted a simplified snippet as is customary in such venues :) A problem I have with the no-parens style is that I can't tell how associativity works (between print, join, map in your case)

Replies are listed 'Best First'.
Re^5: map sub to list?
by Laurent_R (Canon) on Sep 09, 2013 at 19:05 UTC

    You may think of it as a data pipeline from right to left. The 1..4 operator produces a list of values fed as an argument to map; map itself produces here another list of values (2 to 5) fed as argument to join; join produces a string made of the numbers separated by spaces, fed to print. Even though the syntax is quite different, this dataflow programming style of construct is very much in the spirit of the various dialects of Lisp and some other functional languages. You may add parens if you feel more comfortable with them, but with a bit of experience you will probably end up agreeing with my view that the syntax is actually clearer without the parens. If you know Unix and shell programming, think of the | operator (except that, with Perl, you have to read pipeline from right to left).

    Oh, and BTW, once you are a bit more used to Perl (this is probably a bit too early at this point), read Mark-Jason Dominus' book "Higher Order Perl" (PDF available for free on his site), in which he shows that Perl has many features of functional languages, including call back functions, first-class citizen functions, anonymous subroutines, closures, function factories, currying, etc.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-09-28 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (124 votes). Check out past polls.

    Notices?