分数計算
bigratモジュールを使うと分数を扱えます。
use strict; use warnings; use bigrat; my $a = 2/7; my $b = Math::BigRat->new('1/2'); my $c = Math::BigRat->new('0.125'); print $a + $b, "\n"; # 11/14 print $a + $c, "\n"; # 23/56 my $d = 3/8; print $d->numerator(), "\n"; # 3 print $d->denominator(), "\n"; # 8 print $d->numify(), "\n"; # 0.375