in reply to Product of a list of numbers?

Can't say if its more efficient, but you could use List::Util::reduce.

use List::Util 'reduce'; my @a = ( 1, 2, 3, 4, 5 ); print reduce{ $a * $b } @a; 120

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Timing (and a little luck) are everything!

Replies are listed 'Best First'.
Re^2: Product of a list of numbers?
by hippo (Archbishop) on Jun 26, 2022 at 12:41 UTC

    For anyone wishing to do this now, note that since version 1.35 (October 2013) List::Util has had a product function to perform precisely this task.

    #!/usr/bin/env perl use strict; use warnings; use List::Util 1.35 'product'; my @a = (1, 2, 3, 4, 5); print product @a;

    🦛