Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: $foo->bar = 14;

by tadman (Prior)
on Jan 03, 2003 at 22:03 UTC ( #224135=note: print w/replies, xml ) Need Help??


in reply to Re^2: $foo->bar = 14;
in thread $foo->bar = 14;

You don't have to change your API, or use a tie, at least in this case. Something like this, perhaps:
sub read : lvalue { my ($self) = @_; vec($self->{value},0,1); }
I know it's not pretty, but it works.

I didn't mean to say that Perl hasn't worked very well for me, but there are occasions where it has been broken, though admittedly these were in the early days of Perl 5. So far, Perl 5.8 has been wonderful, too, so less experimental than ever before, perhaps.

Replies are listed 'Best First'.
Re^2: $foo->bar = 14;
by adrianh (Chancellor) on Jan 04, 2003 at 21:19 UTC
    I know it's not pretty, but it works.

    True :-) However, I think my basic point still stands. Perl's current implementation of lvalue subs breaks implementation encapsulation - and can therefore make life considerably more complex if you have to change that implementation.

    The classic case of this is when you have an attribute that you later decide can be calculated/set by a runtime method (trading space for speed).

    Perl's lvalue subroutine implementation does not allow you to do this without resorting to tie (or possibly a source filter).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://224135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2020-01-23 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?