in reply to Re: Mixed lvalue/rvalue sub function
in thread Mixed lvalue/rvalue sub function
You C++-ish suggestion:$obj->header('test'); # Get header 'test' $obj->header('test','new value'); # set header test $obj->header; # Get all headers as hash
doesn't work in Perl because there all objects are references (to talk C++: from type *myclass not myclass). So assigning to $hdr_slot would make this variable a string with the value "new value" and would remove the reference to the object. Overloading the '=' operator only is used for generating temp copies for operators like '+=', so far I know.my $hdr_slot = $self->header ('test'); $hdr_slot = "new value"; # Set print "New header: $hdr_slot\n"; # Get
The only way to do this is to tie a class to $hdr_slot. Then you can define a STORE method which gets called at every '='. See 'perldoc perltie' for more.
I read all this in the book 'Object Oriented Perl' just two weeks ago.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Mixed lvalue/rvalue sub function
by elmex (Friar) on Apr 18, 2008 at 13:44 UTC | |
by mscharrer (Hermit) on Apr 18, 2008 at 17:18 UTC |