in reply to Re^6: Assignable Subroutines
in thread Assignable Subroutines
I had the wierdest of thoughts (ain't TMTOWTDI wonderful?) ...
sub update_thing { my ($self, $x, $y, $u) = @_; if (ref $u and UNIVERSAL::isa($u, 'CODE')) { # use temp to keep the $u function from changing $_[0] ;-) my $val = $self->{cell}[$x][$y]; $u = $u->($val); } # validate $u. if ($is_valid) { $self->{cell}[$x][$y] = $u; }
called sorta like:
$obj->update_thing(15000, 20000, sub { $_[0] =~ s[something][else]g; + $_[0] } );
No, not better than $obj->thing(15000,2000) =~ s[something][else]g. But a bit better than the other ideas going around, maybe? :-) If not better, at least different...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Assignable Subroutines
by BrowserUk (Patriarch) on Jan 25, 2005 at 17:28 UTC |