What I don't understood is how it is possible that map can accept different syntax. For example, is it possible to write a perl subroutine that does the same thing, myPerlSub BLOCK LIST
UPDATE: thnx for the explanation!!
I personally believe that you shouldn't be too surprised. Quite a lot of builtin functions accept different kinds of arguments. Just see the first one that springs to mind, e.g. perldoc -f split:
split Splits the string EXPR into a list of strings and returns
list. By default, empty leading fields are preserved, and
trailing ones are deleted. (If all fields are empty, they
considered to be trailing.)
Ok, the case of map is somewhat more surprising: actually, not only is it possible, as others explained to you, to implement the syntax above with Prototypes (which indeed are there much to the objective of letting you write subs that behave like builtins) but it is currently impossible to implement the alternate syntax of map() i.e. namely that with an expression since that would be more akin to to a macro, but there's not provision for such a beast under Perl 5. Of course you can write a sub that accepts a generic argument as the first one and when you use it, then the argument can be an expression, but that would be evaluated and passed to the sub as a scalar, not as an expression to be evaluated by your sub itself.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||