I'm certainly not a guru, and didn't even knew or realized that 'lvalue' exists. So thanks for bringing it up :)

Aside from that, just my opinion: That kind of API is quite weird. I usually write such methods like you did, with an optional $value argument. I guess what I dislike about that lvalue API is, that it looks like action at a distance when skimming through code:

my $v = $self->header ('test') = "fail"; # :-)
vs.:
my $v = $self->header ('test', 'fail');

When you skim over the second example you immediately recognize the missing closing ')'. Of course the first example is also an example of bad formatting, so this might not be an actual issue. I'm just not used to assigning to subroutines.

But that aside: Did you think about returning object handles where you overload the '='? In C++ that is done quite often. Then even this would work:

my $hdr_slot = $self->header ('test'); $hdr_slot = "new value"; # Set print "New header: $hdr_slot\n"; # Get

In reply to Re: Mixed lvalue/rvalue sub function by elmex
in thread Mixed lvalue/rvalue sub function by mscharrer

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.