### Overloaded addition operator sub _add { my ( \$x, \$y ) = @_; my ( \$n_sum, \$sum_str ); my ( \$n1, \$n2 ) = ( \$x->{NUMER}, \$y->{NUMER} ); my ( \$d1, \$d2 ) = ( \$x->{DENOM}, \$y->{DENOM} ); my \$com_denom = ( \$d1 == \$d2 ) ? \$d1 : \$d1 * \$d2; \$n_sum = ( \$d1 == \$d2 ) ? \$n1 + \$n2 : do { \$n1 = \$n1 * ( \$com_denom / \$d1 ); \$n2 = \$n2 * ( \$com_denom / \$d2 ); \$n1 + \$n2; }; my \$gcd = _simplify( \$n_sum, \$com_denom ); ( \$n_sum, \$com_denom ) = map { \$_ /= \$gcd } ( \$n_sum, \$com_denom ); \$sum_str = (\$com_denom) ? ( \$n_sum == \$com_denom ) ? "1" : "\${n_sum}/\${com_denom}" : "0"; return \$sum_str; } ### Overloaded subtraction operator sub _sub { my ( \$x, \$y, ) = @_; my ( \$n_diff, \$diff_str ); my ( \$n1, \$n2 ) = ( \$x->{NUMER}, \$y->{NUMER} ); my ( \$d1, \$d2 ) = ( \$x->{DENOM}, \$y->{DENOM} ); my \$com_denom = ( \$d1 == \$d2 ) ? \$d1 : \$d1 * \$d2; \$n_diff = ( \$d1 == \$d2 ) ? \$n1 - \$n2 : do { \$n1 = \$n1 * ( \$com_denom / \$d1 ); \$n2 = \$n2 * ( \$com_denom / \$d2 ); \$n1 - \$n2; }; my \$gcd = _simplify( abs(\$n_diff), \$com_denom ); ( \$n_diff, \$com_denom ) = map { \$_ /= \$gcd } ( \$n_diff, \$com_denom ); \$diff_str = (\$com_denom) ? ( \$n_diff == \$com_denom ) ? "1" : "\${n_diff}/\${com_denom}" : "0"; return \$diff_str; }