You need to evaluate the string "6/2" to get the numerical value 3 before you try to do the addition. You can do it using eval but eval on strings is dangerous as it will *execute* the code in the string. This function should be safe to use as it will only do the eval if the string contains + - . 0 1 2 3 4 5 6 7 8 9 / plus spaces and tabs which are harmless. These chars should be all you need for the task at hand....
sub frac2dec { my $str = shift; $str = eval $str if $str =~ m!^[\-\+\d\./ \t]+$!; $str; } $a = " 6/2"; $b = " 4 / 8 "; print frac2dec($a) + frac2dec($b); __DATA__ 3.5
cheers
tachyon
In reply to Re: Arithmetic with fractions
by tachyon
in thread Arithmetic with fractions
by algonquin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |