It just happens that if a map is used in a scalar context, it returns the number of items it would have created had it been used as a list. But it just as easily could return the day of the year instead (although not quite as useful).
Perl 5 uses documentation to explain the implementation so saying "it is documented to return the number of elements in scalar context so it can't just as easily return the day of year instead" doesn't hold much water. Fortunately, Perl 6 is intended to have a complete specification allowing for any number of implementations. This has nothing to do with the issue I wanted to make though.
Your wording to me implies that map doesn't actually create the elements it counts. The docs say "In scalar context, returns the total number of elements so generated." which implies to me they are created. I know that there could be an optimization not to actually build up the return list such as happens when map is called in a void context with recent versions. If indeed it is as you say, a doc patch should be submitted to clarify.
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.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||