Kurt D. Starsinic on Tue, 25 Apr 2000 19:26:07 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Perl 5.6 question


On Tue, Apr 25, 2000 at 07:02:02PM -0400, Joe Smith wrote:
> On Tue, Apr 25, 2000 at 03:58:58PM -0400, mjd-perl-pm@plover.com wrote:
> > 
> > > Perl 5.6 question: Why would you want to use an lvalue sub?
> > 
> > Suppose you have an object, $car.  $car has a piece of member data
> > called `color'.
> > 
> >         $the_color = $car->color();
> > 
> > This gets the car's color.
> > 
> >         $car->color() = 'blue';
> > 
> > This sets the car's color to blue.
> 
> Duh!  Now I get it.  Much nicer to read than: $car->color('blue').
> Too bad this example wasn't in the 'What's New' article that came out
> last week.
> 
> What does this look like in the method?  Is it as simple as
> 
>   sub color:lvalue { $_[0]->{'_color'} }
> 
> Can subs be marked :'lvalue' dynamically, so AUTOLOAD can whip up such
> nifty attribute accessors on-the-fly?
> 
> Is it easy to code something that still accepts a new value as an
> argument, for compatibility?
> 
>   sub color:lvalue { @_ > 1 ? $_[0]->{'_color'} = $_[1] : $_[0]->{'_color'} }

    These all sound like great research questions.  Why don't you
download and install 5.6, try some things, and let us all know what
you think?  Is it usable, intuitive, fast?  Practical experience always
beats abstract speculation, in my book.

    Peace,
* Kurt Starsinic (kstar@orientation.com) ---------- Senior Network Engineer *
|          `The term `Internet' has the meaning given that term in          |
|           section 230(f)(1) of the Communications Act of 1934.'           |
|           -- H.R. 3028, Trademark Cyberpiracy Prevention Act              |

**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**