Richard Clamp wrote:
@_ will still have an element in it after shifting off $self, so the
old favourite:

 sub foo {
     my $self = shift;
     if (@_) {
         $self->{foo} = shift;
     }
     $self->{foo}; # or $self;
 }

Will still have something to assign.

While I'm not a golfer and am usually all for readable code, that has to be too much code for just an accessor :)


sub foo { @_==2 ? shift->{foo} = shift : shift->{foo} }

Assuming you don't return the object.

--
Robin Berjon <[EMAIL PROTECTED]>
Research Scientist, Expway      http://expway.com/
7FC0 6F5F D864 EFB8 08CE  8E74 58E6 D5DB 4889 2488




Reply via email to