An LVALUE is a value that is a literal like a "constant," therefore it cannot be modified.

An lvalue is something that can be used on the "l"eft of an assignment operator. It pretty much means "something modifiable", the opposite of what you said.

ref returns LVALUE for references to PVLV scalars. PVLV scalars are returned by some operations which need to produce a scalar whose modification has side-effects. Those operators are keys, pos, substr and vec. (They only return a PVLV when used in an lvalue context.)

For example,

my $x = "def"; say ref( \substr( $x, 0, 0 ) ); # LVALUE substr( $x, 0, 0 ) = "abc"; say $x; # abcdef
my $x = "def"; my $r = \substr( $x, 0, 0 ); say ref( $r ); # LVALUE $$r = "abc"; say $x; # abcdef

Because we can't just do ref($_[0]) because it's not a reference

True, but contrary to what you said, $REF = \$_[0]; ref( $REF ) does work.

$ perl -Mv5.014 -e' sub f { my $REF = \$_[0]; say ref( $REF ); } f substr( "", 0, 0 ); ' LVALUE

That said, all you need is ref( \$_[0] ).

$ perl -Mv5.014 -e' sub f { say ref( \$_[0] ); } f substr( "", 0, 0 ); ' LVALUE

In reply to Re: How to find out if an argument is an LVALUE ? by ikegami
in thread How to find out if an argument is an LVALUE ? (TinyPerl) by harangzsolt33

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.