in reply to Multiplying together the numers in an array

Here is a stupid but concise way for your amusement:
print eval join "*", @numbers;

Replies are listed 'Best First'.
Re: Re: Multiplying together the numers in an array
by ambrus (Abbot) on Apr 10, 2004 at 09:42 UTC

    And you can also lose precision by stringifying the numbers:

    @a= (1/3, 3); $prod1= eval join "*", @a; $prod2= 1; $prod2*= $_ for @a; print $prod1,$/, $prod2,$/;
    outputs
    0.999999999999999 1

    I'm not trying to attack you, but this can be a trap at other times when you store floating-point numbers as text. I learned in when I wrote the obfu Fun with duff's device and AUTOLOAD.

    Also look at what happens if the numbers are object with stringification. Look:

    use Math::Complex; @a= (1+i, 2); $prod1= eval join "*", @a; $prod2= 1; + $prod2*= $_ for @a; print $prod1,$/, $prod2,$/;
    output is:
    1+2i 2+2i
Re: Re: Multiplying together the numers in an array
by ambrus (Abbot) on Apr 09, 2004 at 21:01 UTC

    And that will fail if some of the numbers is a NaN or Infinity.

      I said it was stupid.