In non-lvalue context, you can return the direct variable. It doesn't matter if the lvalue is "ever" modified -- only at that point when it is dereferenced. It isn't returned if you are taking a reference to it.

Sorry, but I think I've been more than patient. That's BS!

Its BS, because you cannot ever know if it is called "In non-lvalue context". Perl provides no mechanism to give you that information.

Wishing it were so does not make it so. Stridently concluded that "you can"; on the basis of your fantasy that you could if perl gave you the information; is stupid.

Stupid, because Perl cannot give you that information!.

Another attempt. This time, try reading the code and understanding it -- not your fantasy vision of it:

sub x :lvalue{ ...; $something } ... someFunc( x() );

The value returned from x() is passed to somefunc() as $_[0]; if somefunc() modifies $_[0], it also modifies $something within x(). Perl cannot know if it does!

And someFunc() might do someOtherFunc( $_[0] ); And if someOtherFunc() modifies it's version of $_[0], it will also modify $something in x().

And if someOtherFunc() calls someOtherOtherFunc( $_[0] ); And if someOtherOtherFunc() modifies it's version of $_[0], then it will also modify $something.

And if someOtherOtherFunc()....

It is not possible for Perl to delve into all the calling code; and all the code it calls, and all the code that code calls through to the end of the program run to determine if anything will/could/might modify the lvalue x() returns.

And wish and prevaricate as much as you like; it ain't never gonna happen.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

In reply to Re^13: can sub check context for lvalue vs rvalue context? by BrowserUk
in thread can sub check context for lvalue vs rvalue context? by perl-diddler

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.