Maybe I've taken references to a few different subs and passed them around, and then at some point call whichever one has been passed? Maybe some other sub returns a scalar, a hashref, a list, or whatever. What happens if I want to use the sub that refuses to be used in list context or scalar context?

Well I can wrap it in another sub, maybe an anonymous sub, which doesn't seem like a heart-rending, mind-warping workaround. Should wrapping it be necessary? Who's to say, really? If someone wants to return any kind of user data or status information, it would require the wrapper anyway since the author didn't return anything from the original sub. One might as well have the wrapper call it in void context then return whatever you like.


In reply to Re^2: Best practices for warnings about wrong context by mr_mischief
in thread Best practices for warnings about wrong context by vsespb

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.