in reply to regex transforms of object attributes
If your class lends itself to the technique, you could use an lvalue method and avoid the need to copy anything.
#! perl -slw use strict; package Test; sub new{ my( $class, $value ) = @_; return bless { content => $value }, $class; } sub content : lvalue { my( $self ) = shift; $self->{ content }; } 1; package main; my $thing = Test->new( 'empty' ); print $thing->content; $thing->content = 'the quick brown fox'; print $thing->content; $thing->content =~ s[\b(.)][\U$1]g; print $thing->content; __END__ P:\test>368057 empty the quick brown fox The Quick Brown Fox
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex transforms of object attributes
by ambrus (Abbot) on Jun 20, 2004 at 20:20 UTC | |
by BrowserUk (Patriarch) on Jun 20, 2004 at 22:14 UTC | |
by ihb (Deacon) on Jun 20, 2004 at 22:20 UTC |