Well, I'm currently confortable with C++ references. Although the name is the same, the syntax is different. In C++ I can write:
int &pluto = pippo;
and, from now on (up to the end of its scope), pluto is just a synonim for pippo. I'am not asserting I can do this for an object member.

In C++, if I have a class member named data, in a method of that class I can simply refer to it as data, which is the same as this->data. In Perl, the same member must be referred to as $this->{data}, in addition to explicitely setting the object pointer every time: my $this = shift;, for instance.

But, if I store a reference, I am obliged to refer to the corresponding scalar as ${$this->{data}}, and this clutters the code way too much for me ($$data would be acceptable) . Please, tell me that I am wrong and I can save all this typing.

Moreover, just saving a reference to an argument as a class member is not completely satisfactory. The top of my dreams would be that the passed buffer becomes a private member, i.e. it is not possible to modify it from outside the constructor by referring to the actual argument:

read(IN, $buffer, 1000000); push @mysegments, new MyPackage::MySegment($buffer); print "+$buffer+"; # gives ++
but the buffer is still living as a private member in my object.

In reply to Re: Re: How to swap scalar values without copies by Anonymous Monk
in thread How to swap scalar values without copies by Anonymous Monk

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.