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.
In reply to Re^2: Mixed lvalue/rvalue sub function
by mscharrer
in thread Mixed lvalue/rvalue sub function
by mscharrer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |