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":



  • 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.