I didn't know that about the changes to qw//.

I've had some rude surprises when I've written subs that were intended to return lists. That's why I always use an intermediate variable or an explicit wantarray call in when I write a sub that will normally return a list. Things like return 7..5 can have surprising effects in scalar context.

Most of the time, a sub that returns a list should act like an array in scalar context, assigning to an intermediate array is a simple way to get context aware results. When other behavior is desired, I prefer to explicitly construct the result set using wantarray.

sub seven_in_scalar_context { my @r = 3..9; return @r; } sub nine_in_scalar_context { my @r = 3..9; return wantarray ? @r : $r[-1]; }

Array behavior in scalar context is pretty well known, so I feel good about using it implicitly. I've seen too many questions about other kinds of contextual returns (especially the regarding the comma) to feel good about using them implicitly. So I use wantarray everywhere else.


TGI says moo


In reply to Re^5: most appropriate return data type by TGI
in thread most appropriate return data type by Anonymous Monk

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.