Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

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

It strikes me that the thing that prevents validation of values assigned to lvalue subs, is the way in which the lvalue is determined--by being the last line/value of the sub.

If there were a keyword that allowed the programmer to indicate what the lvalue was, he could choose where in the sub that lvalue was positioned and control could be returned to the sub after the assignment has taken place.

sub thing { my( @args ) = @_; ... code to determine what the lvalue should be. LVALUE{ $lvalue }; if( $lvalue eq some condition ) { ... take positive action; } else { ... take negative action; } }

In use, the interpreter would run the code until the (or a?) LVALUE statement is encountered. This is directly equivalent to the current situation of running the sub to determine the lvalue. Once obtained, the LVALUE would be available to the calling code to use in whatever manner. Once the statement that called the sub completes, the remainder of the sub would be run, with the assigned value in place for veryification or whatever else the programmer might wish to do to it.

There are probably a gazillion reasons why this won't work, but it seems to address most of the issues raised, whilst providing for inline, intuative validation.

The main advantage I see of this over tieing, is that the validation code is at the same scope as the the lvalue determination code.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

In reply to Re: Assignable Subroutines by BrowserUk
in thread Assignable Subroutines by dragonchild

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 chilling in the Monastery: (2)
As of 2024-04-19 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found