in reply to Re: How to swap scalar values without copies
in thread How to swap scalar values without copies
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.int &pluto = pippo;
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:
but the buffer is still living as a private member in my object.read(IN, $buffer, 1000000); push @mysegments, new MyPackage::MySegment($buffer); print "+$buffer+"; # gives ++
|
|---|