in reply to Surviving 'Illegal division by zero'
use strict; use warnings; { package MyNumber; use overload '0+' => \&numify, '/' => \&division; use Scalar::Util; my %numbers; BEGIN {*MyNumber::__ = \&Scalar::Util::refaddr} sub DESTROY {delete $numbers {__ shift}} sub new {my $f; bless \$f => shift} sub set {$numbers {__ $_ [0]} = $_ [1]; $_ [0]} sub numify {$numbers {__ $_ [0]}} sub division {my $f = $numbers {__ $_ [0]}; my $s = ref ($_ [1]) =~ /MyNumber/ ? $numbers {__ $_ + [1]} : $_ [1]; ($f, $s) = ($s, $f) if $_ [2]; $s ? $f / $s : undef} } my $fig_1 = MyNumber -> new -> set (get_numeric_value_from_xml (...)) +; my $fig_2 = MyNumber -> new -> set (get_numeric_value_from_xml (...)) +; my $growth = 100 * $fig_1 / $fig_2 - 100;
Abigail
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Surviving 'Illegal division by zero'
by ViceRaid (Chaplain) on Jun 23, 2004 at 12:10 UTC | |
by dragonchild (Archbishop) on Jun 23, 2004 at 14:36 UTC | |
by ViceRaid (Chaplain) on Jun 23, 2004 at 22:17 UTC | |
by melora (Scribe) on Jun 24, 2004 at 02:34 UTC | |
Re^2: Surviving 'Illegal division by zero'
by dragonchild (Archbishop) on Jun 24, 2004 at 12:08 UTC | |
by Abigail-II (Bishop) on Jun 24, 2004 at 12:20 UTC |
In Section
Seekers of Perl Wisdom