in reply to Trying to get sum of elements in array

my $sum = () = map { (1)x$_ } @array;

Of course. ;-p

- tye        

Replies are listed 'Best First'.
Re^2: Trying to get sum of elements in array (map)
by BillKSmith (Monsignor) on Feb 05, 2015 at 23:22 UTC
    Or use a module.
    use strict; use warnings; use List::Util qw(sum); print 'The sum is : ', sum(map {rand 50} 1..5), "\n";
    Bill
Re^2: Trying to get sum of elements in array (evil eval)
by Discipulus (Canon) on Feb 06, 2015 at 08:56 UTC
    or the evil evil way to do it... ;=)
    perl -e " print eval join '+',@ARGV " 16 30 21 7 11 85


    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.