in reply to regex transforms of object attributes
where the content method would recognize the code ref and treat the current value as $_ within it. Something vaguely like:$self->content(sub{s/foo/bar/g});
Another spiffy (but experimental) technique would be to make the content method an lvalue subroutine. So you could write the one-linersub content { my $self = shift; if (@_) { my $set = shift; if (isa($set,"CODE")) { # fixed :-) &$set for $self->{'content'}; # Code to modify content (as + $_) gets executed } else { $self->{'content'} = $set; # Direct set } } $self->{'content'}; }
$self->content =~ s/foo/bar/g; # instead of # $self->content(map { s/foo/bar/g } map $_, $self->content);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex transforms of object attributes
by belden (Friar) on Jun 18, 2004 at 23:50 UTC |