in reply to Math::BigPositiveOkayPrecision prototype
sub compute { my( $opsub, $x, $y, $rev )= @_; $y= $x->new( $y ) if ! ref $y; ( $x, $y )= ( $y, $x ) if $rev; return $opsub->($x,$y); }
This would allow you to simplify the operation methods in a manner similar to that below.
sub mul { my $mulsub = sub { bless \( $$_[0] + $$_[1] ) }; return &compute($mulsub,@_); }
This may have adverse effects on performance since it increases the number of function calls, but I'm not experienced enough to know how much. However, it might make your code easier to understand and maintain.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Math::BigPositiveOkayPrecision prototype (refactored)
by tye (Sage) on Aug 08, 2007 at 21:34 UTC |