> If the explanation is that map is being called in scalar context, then the following is unexpected:

no! whatever comes after return is executed in the context of the sub's call.

so in this case¹ $name = scalar @out

It's true many people expect a LIST to be returned but thats generally wrong in scalar context.

A helper routine  sub listify { (@_)[0..$#_] } might help to assure this "expected" behaviour, whenever you need to return a LIST².

Cheers Rolf

( addicted to the Perl Programming Language)

PS: please read the thread I linked before asking more questions.

¹) which isn't the code from the post I replied to, where a map-statement is returned

UPDATE

> Clever, but not elegant.

Larry will be so devastated to hear this ... :´(

UPDATE

²) FWIW

DB<112> sub listify { (@_)[0..$#_] } DB<113> sub tst { listify map{lc} @_ } DB<114> $s =tst("A".."D") => "d" DB<115> @l =tst("A".."D") => ("a", "b", "c", "d")

In reply to Re^3: wantarray alternative by LanX
in thread wantarray alternative by tqisjim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.