Note that the context doesn't tell you what happens with the return values or what the user wants to do.

For instance, in this common idiom, function() is in list context but I want to the output in @values, not printed. I wouldn't like functions that try to be smarter than me.

my @values = map { function( $_ ) } @input;

Every time I've thought it would be good to simply print to STDOUT, someone comes along and wants the output in some other way. Instead of making the function know that stuff, I let the user decide. I can always make a print_function() that does that and still lets me use the "dumb" version/ :)

--
brian d foy <brian@stonehenge.com>

In reply to Re: How much can a function know about the context in which it is called? by brian_d_foy
in thread How much can a function know about the context in which it is called? by jacques

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.