Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The more I think about it the more I'm convinced that using lex-refs like in this post is the best KISS approach without using extra moduls.

$lamb=sub { my($x,$y)=\(@_); $$x += $$y }

You just have to restrict referencing to arguments which are read/write and copying to read-only args.

Such that $$x signals clearly "x is an alias" and $y "y is only a copy".

 $lamb=sub { my $x= \shift; my ($y)=@_; $$x += $y }

Your code becomes much clearer and unintended changes to the original of $y are impossible, avoiding ugly and very hard to track bugs!!!

Unfortunately its not possible to write this as dense (but more error-redundant) than in ruby...

$lamb=sub { my ($$x,$y)=@_; $$x += $y } # Can't declare scalar dereference in "my"

But maybe I'm missing another "way to do it"? ( would be please to know 8)

UPDATE: Of course you can use arraslices

 $a=sub { my($x,$y)=(\(@_[0]),@_[1]); $$x +=$y }

or

 $a=sub { my($x,$y)=(\($_[0]),$_[1]); $$x +=$y }

link to footnotes within my own comment, so I'll just leave others to navigate manually.

sure you can define anchor-names with a-tags and link to them with href to #name. E.g these KISSes are interlinked. Just look in the HTML-Source...

But I doubt footnotes may help clarify your update-inferno... ;-)

Cheers Rolf


In reply to Re: Local for lexicals by LanX
in thread Local for lexicals by JadeNB

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 studying the Monastery: (4)
As of 2024-04-25 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found