Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You missed one part of the trick. The body of an lvalue sub doesn't get executed when it is used as an lvalue. The trick works only if the last expression is an lvalue (as is trinary op). That means you do no good to shift in or copy the function arguments. $key and $self in your example are undefined when called as an lvalue.

Arguments are still usable, but you need to initialize them in the last line of the sub. Here's a minimal rewrite.

sub get_set :lvalue { my $junk; key_ok( $_[1] ) ? $_[0]->{ $_[1] } : $junk; }
Note that $junk is effectively a package global variable holding the last value assigned with a not-ok $key. You can retrieve it with $foo->get_set($bad_key), but the value returned is for any $foo of the class.

After Compline,
Zaxo


In reply to Re: Experimenting with Lvalue Subs by Zaxo
in thread Experimenting with Lvalue Subs by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found