harry34 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a list of variables of the type tmp1[$i][$j]
They all contain a fraction (i.e 1/4). How can I evaluate these fractions
into variables of the type ($frac[$i][$j]).

cheers for your help.
harry

Edit ar0n -- title change (was: eval)

Replies are listed 'Best First'.
Re: eval
by talexb (Chancellor) on Dec 20, 2001 at 21:30 UTC
    If you want to evaluate them for their value (like 1/4 => .25), you could use eval().

    If you want to split them into the numerator and the denominator, you could use split() on the '/' character (assuming that they are simple fractions and not expressions that need more complex evaluation).

    "Excellent. Release the hounds." -- Monty Burns.

      They are fractions (i.e 1/4 etc) and I do want to evaluate them for there decimal values (i.e 0.25).
      How do I use the eval function to do this ?
      and store each decimal number in a variable of type FRAC [$i][$j]
        $frac = '1/4'; $dec = eval $frac; print "$frac = $dec";

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        You could always look up the eval function to find out.
        why do you need them to be in that format, and what exactly do you mean by it? If all you are looking for is the decimal equiv, just use perl
        $eval = (1/4); print $eval; 0.25
        I may be off the mark, but I hate the way sometimes people try to make this completely obscure code on here when sometimes simple is clearly better. If using eval has a better purpose for THIS PARTICULAR ISSUE, i would love to hear it.
Re: evaluating fractions
by Fastolfe (Vicar) on Dec 21, 2001 at 01:48 UTC
Re: evaluating fractions
by gt8073a (Hermit) on Dec 20, 2001 at 22:12 UTC

    is this homework

    Will perl for money
    JJ Knitis
    (901) 756-7693
    gt8073a@industrialmusic.com