Ahh, I understand now. Quite simple, yet very effective. I'm a mechanical engineer, so I find the your problem interesting. One suggestion that I would make (although it may not help that much) would be to make the individual operation methods simpler by extracting their common code to another method. For instance, the beginning portions of
mul, div, pow, add, shl, shr, cmp, prd are all practically identical. You could write:
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.