Actually, the third argument doesn't indicate whether the statement is in void context, but rather whether the statement is an assignment varient. Here's the relevant section from perldoc overload:


Calling Conventions for Binary Operations

The functions specified in the use overload ... directive are called with three (in one particular case with four, see the section on Last Resort) arguments. If the corresponding operation is binary, then the first two arguments are the two arguments of the operation. However, due to general object calling conventions, the first argument should always be an object in the package, so in the situation of 7+$a, the order of the arguments is interchanged. It probably does not matter when implementing the addition method, but whether the arguments are reversed is vital to the subtraction method. The method can query this information by examining the third argument, which can take three different values:

FALSE the order of arguments is as in the current operation.
TRUE the arguments are reversed.
undef the current operation is an assignment variant (as in $a+=7), but the usual function is called instead. This additional information can be used to generate some optimizations. Compare the section on Calling Conventions for Mutators.


The point is so that you can distinguish between

print($obj += 6);

and

print($obj + 6);

They should both print the same thing, but in the first case $obj should be increased by 6 and in the second case it shouldn't.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."


In reply to Re: Re: Re: Re: Squeezing $a+1 to be magical like $a++ by davorg
in thread Squeezing $a+1 to be magical like $a++ by coolmichael

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.